Skip to content

Commit

Permalink
Bugfix: unexpected string endings
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 15, 2015
1 parent 5bc9130 commit 1490291
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
5 changes: 2 additions & 3 deletions json/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,12 @@ func (p *Parser) consumeStringToken() bool {
p.r.Move(1)
break
} else if c == 0 {
break
return false
} else if c == '\\' {
if p.r.Peek(1) != 0 {
p.r.Move(1)
} else {
p.r.Move(1)
break
return false
}
}
p.r.Move(1)
Expand Down
7 changes: 2 additions & 5 deletions json/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func assertGrammars(t *testing.T, s string, grammartypes ...GrammarType) {
tt, _ := p.Next()
if tt == ErrorGrammar {
assert.Equal(t, io.EOF, p.Err(), "error must be EOF in "+stringify)
assert.Equal(t, len(grammartypes), i, "when error occurred we must be at the end in "+stringify)
assert.Equal(t, len(grammartypes), i, "when error occurred we must be at the end in "+s)
break
} else if tt == WhitespaceGrammar {
continue
Expand Down Expand Up @@ -99,10 +99,6 @@ func TestGrammars(t *testing.T) {
assertGrammars(t, `{"a": [1, 2], "b": {"c": 3}}`, StartObjectGrammar, StringGrammar, StartArrayGrammar, NumberGrammar, NumberGrammar, EndArrayGrammar, StringGrammar, StartObjectGrammar, StringGrammar, NumberGrammar, EndObjectGrammar, EndObjectGrammar)
assertGrammars(t, "[null,]", StartArrayGrammar, LiteralGrammar, EndArrayGrammar)

// early endings
assertGrammars(t, "\"a", StringGrammar)
assertGrammars(t, "\"a\\", StringGrammar)

assert.Equal(t, "Whitespace", WhitespaceGrammar.String())
assert.Equal(t, "Invalid(100)", GrammarType(100).String())
assert.Equal(t, "Value", ValueState.String())
Expand All @@ -121,6 +117,7 @@ func TestGrammarsError(t *testing.T) {
assertGrammarsError(t, "{\"a\" 1}", ErrBadObjectDeclaration)
assertGrammarsError(t, "1.", ErrNoComma)
assertGrammarsError(t, "1e+", ErrNoComma)
assertGrammarsError(t, `{"":"`, io.EOF)
}

func TestStates(t *testing.T) {
Expand Down

0 comments on commit 1490291

Please sign in to comment.