Skip to content

Add a check for redundant . and e in number parser#89

Open
vearutop wants to merge 1 commit intovalyala:masterfrom
vearutop:parse-number
Open

Add a check for redundant . and e in number parser#89
vearutop wants to merge 1 commit intovalyala:masterfrom
vearutop:parse-number

Conversation

@vearutop
Copy link

@vearutop vearutop commented Feb 6, 2023

This PR naively fixes false positive parsing of an invalid number that contains more than one . or e.
#88 (comment)

package main

import (
	"fmt"

	"github.com/valyala/fastjson"
)

func main() {
	v, err := fastjson.ParseBytes([]byte(`[127.0.0.1]`))
	if err != nil {
		fmt.Println("failed:", err.Error())
	} else {
		fmt.Println("passed:", v.Type())
	}

	err = fastjson.ValidateBytes([]byte(`[127.0.0.1]`))
	if err != nil {
		fmt.Println("validation failed:", err.Error())
	}

	// Output:
	// passed: array
	// validation failed: cannot parse JSON: cannot parse array: missing ',' after array value; unparsed tail: ".0.1]"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant