Skip to content

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

@PhilipBorgesen

Description

@PhilipBorgesen

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions