hcl/json: Fix incorrect alphabetical check in scanner
This commit is contained in:
parent
f7764c6954
commit
c27cd9b2e8
@ -153,7 +153,7 @@ func byteCanStartKeyword(b byte) bool {
|
|||||||
// in the parser, where we can generate better diagnostics.
|
// in the parser, where we can generate better diagnostics.
|
||||||
// So e.g. we want to be able to say:
|
// So e.g. we want to be able to say:
|
||||||
// unrecognized keyword "True". Did you mean "true"?
|
// unrecognized keyword "True". Did you mean "true"?
|
||||||
case b >= 'a' || b <= 'z' || b >= 'A' || b <= 'Z':
|
case isAlphabetical(b):
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
@ -167,7 +167,7 @@ Byte:
|
|||||||
for i = 0; i < len(buf); i++ {
|
for i = 0; i < len(buf); i++ {
|
||||||
b := buf[i]
|
b := buf[i]
|
||||||
switch {
|
switch {
|
||||||
case (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_':
|
case isAlphabetical(b) || b == '_':
|
||||||
p.Pos.Byte++
|
p.Pos.Byte++
|
||||||
p.Pos.Column++
|
p.Pos.Column++
|
||||||
default:
|
default:
|
||||||
@ -291,3 +291,7 @@ func posRange(start, end pos) hcl.Range {
|
|||||||
func (t token) GoString() string {
|
func (t token) GoString() string {
|
||||||
return fmt.Sprintf("json.token{json.%s, []byte(%q), %#v}", t.Type, t.Bytes, t.Range)
|
return fmt.Sprintf("json.token{json.%s, []byte(%q), %#v}", t.Type, t.Bytes, t.Range)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAlphabetical(b byte) bool {
|
||||||
|
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z')
|
||||||
|
}
|
||||||
|
@ -810,6 +810,27 @@ func TestScan(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`&`,
|
||||||
|
[]token{
|
||||||
|
{
|
||||||
|
Type: tokenInvalid,
|
||||||
|
Bytes: []byte(`&`),
|
||||||
|
Range: hcl.Range{
|
||||||
|
Start: hcl.Pos{
|
||||||
|
Byte: 0,
|
||||||
|
Line: 1,
|
||||||
|
Column: 1,
|
||||||
|
},
|
||||||
|
End: hcl.Pos{
|
||||||
|
Byte: 1,
|
||||||
|
Line: 1,
|
||||||
|
Column: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user