Skip to content

Commit

Permalink
Fixes bug with handling of empty identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Jan 1, 2018
1 parent 2655679 commit cd6ec77
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ language: go

go:
- 1.7
- 1.8
- 1.9
- tip
2 changes: 1 addition & 1 deletion identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var reservedWords = map[string]bool{
// a key with spaces -> false
// 1startsWithANumber -> false
func validIdentifier(s string) bool {
if reservedWords[s] {
if reservedWords[s] || s == "" {
return false
}

Expand Down
3 changes: 3 additions & 0 deletions identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func TestValidIdentifier(t *testing.T) {
{"true", false},
{"else", false},
{"null", false},

// Empty string
{"", false},
}

for _, test := range tests {
Expand Down
1 change: 0 additions & 1 deletion script/precommit
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ PROJDIR=$(cd `dirname $0`/.. && pwd)
cd ${PROJDIR}

./script/test
./script/lint
4 changes: 3 additions & 1 deletion statements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func TestStatementsSimple(t *testing.T) {
"foo": "bar"
},
"else": 1,
"id": 66912849
"id": 66912849,
"": 2
}`)

ss, err := statementsFromJSON(bytes.NewReader(j), statement{{"json", typBare}})
Expand All @@ -52,6 +53,7 @@ func TestStatementsSimple(t *testing.T) {
`json.anob.foo = "bar";`,
`json["else"] = 1;`,
`json.id = 66912849;`,
`json[""] = 2;`,
})

t.Logf("Have: %#v", ss)
Expand Down

0 comments on commit cd6ec77

Please sign in to comment.