Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: Extra space in Decoder.Token SyntaxError messages #26587

Closed
PhilipBorgesen opened this issue Jul 25, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@PhilipBorgesen
Copy link
Contributor

commented Jul 25, 2018

Decoder.Token returns SyntaxError with messages containing double spaces after the quoted character (via Decoder.tokenError):

func (dec *Decoder) tokenError(c byte) (Token, error) {
	var context string
	switch dec.tokenState {
	case tokenTopValue:
		context = " looking for beginning of value"
	case tokenArrayStart, tokenArrayValue, tokenObjectValue:
		context = " looking for beginning of value"
	case tokenArrayComma:
		context = " after array element"
	case tokenObjectKey:
		context = " looking for beginning of object key string"
	case tokenObjectColon:
		context = " after object key"
	case tokenObjectComma:
		context = " after object key:value pair"
	}
	return nil, &SyntaxError{"invalid character " + quoteChar(c) + " " + context, dec.offset()}
}

I found this when building a test suite under go version go1.10 darwin/amd64, but it is still an issue as per current HEAD of the master branch: https://github.com/golang/go/blob/master/src/encoding/json/stream.go#L474

I intend to contribute a patch, this issue is mainly to serve as reference and avoid duplication of effort (however small it may be).

@gopherbot

This comment has been minimized.

Copy link

commented Jul 25, 2018

Change https://golang.org/cl/125775 mentions this issue: encoding/json: eliminate superfluous space in Decoder.Token error messages

@mvdan

This comment has been minimized.

Copy link
Member

commented Jul 25, 2018

This isn't a regression from 1.10 and we're very late into the code freeze, so I'm putting this down for 1.12. Thanks for the fix!

@mvdan mvdan added this to the Go1.12 milestone Jul 25, 2018

@mvdan mvdan added the NeedsFix label Jul 25, 2018

@PhilipBorgesen

This comment has been minimized.

Copy link
Contributor Author

commented Jul 25, 2018

You're welcome!

Do I need to do anything when 1.11 is released to continue beyond re-merging from master?

@mvdan

This comment has been minimized.

Copy link
Member

commented Jul 25, 2018

You don't need to do anything other than respond to reviews and fix any conflicts if they emerge. We should get to this CL along with all the others waiting for the freeze to be over.

@PhilipBorgesen

This comment has been minimized.

Copy link
Contributor Author

commented Jul 25, 2018

Ok, thank you!

@gopherbot gopherbot closed this in 97c7e0e Aug 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.