json: fix overly-greedy keyword scanning

Logic error in the scanner caused it to always consume the remainder of
the string.
This commit is contained in:
Martin Atkins 2017-05-16 07:23:33 -07:00
parent bd0cbc1c81
commit 8dfc3c4bbe
2 changed files with 69 additions and 1 deletions

View File

@ -165,7 +165,7 @@ Byte:
for i = 0; i < len(buf); i++ {
b := buf[i]
switch {
case b >= 'a' || b <= 'z' || b >= 'A' || b <= 'Z' || b == '_':
case (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_':
p.Pos.Byte++
p.Pos.Column++
default:

View File

@ -510,6 +510,74 @@ func TestScan(t *testing.T) {
},
},
},
{
`[true]`,
[]token{
{
Type: tokenBrackO,
Bytes: []byte(`[`),
Range: zcl.Range{
Start: zcl.Pos{
Byte: 0,
Line: 1,
Column: 1,
},
End: zcl.Pos{
Byte: 1,
Line: 1,
Column: 2,
},
},
},
{
Type: tokenKeyword,
Bytes: []byte(`true`),
Range: zcl.Range{
Start: zcl.Pos{
Byte: 1,
Line: 1,
Column: 2,
},
End: zcl.Pos{
Byte: 5,
Line: 1,
Column: 6,
},
},
},
{
Type: tokenBrackC,
Bytes: []byte(`]`),
Range: zcl.Range{
Start: zcl.Pos{
Byte: 5,
Line: 1,
Column: 6,
},
End: zcl.Pos{
Byte: 6,
Line: 1,
Column: 7,
},
},
},
{
Type: tokenEOF,
Range: zcl.Range{
Start: zcl.Pos{
Byte: 6,
Line: 1,
Column: 7,
},
End: zcl.Pos{
Byte: 6,
Line: 1,
Column: 7,
},
},
},
},
},
{
`""`,
[]token{