Skip to content

Commit d99adc5

Browse files
committed
Fix parsing of values
This fixes the problem that calling Get on simple values would fail: data := []byte("0") value, dataType, offset, err := Get(data) // err == "Value looks like Number/Boolean/None, but can't find its end: ',' or '}' symbol"
1 parent f04e003 commit d99adc5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func tokenEnd(data []byte) int {
3131
}
3232
}
3333

34-
return -1
34+
return len(data)
3535
}
3636

3737
// Find position of next character which is not whitespace

parser_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@ type GetTest struct {
3939
}
4040

4141
var getTests = []GetTest{
42+
// Trivial tests
43+
GetTest{
44+
desc: "read string",
45+
json: `""`,
46+
isFound: true,
47+
data: ``,
48+
},
49+
GetTest{
50+
desc: "read number",
51+
json: `0`,
52+
isFound: true,
53+
data: `0`,
54+
},
55+
GetTest{
56+
desc: "read object",
57+
json: `{}`,
58+
isFound: true,
59+
data: `{}`,
60+
},
61+
GetTest{
62+
desc: "read array",
63+
json: `[]`,
64+
isFound: true,
65+
data: `[]`,
66+
},
67+
GetTest{
68+
desc: "read boolean",
69+
json: `true`,
70+
isFound: true,
71+
data: `true`,
72+
},
73+
4274
// Found key tests
4375
GetTest{
4476
desc: "handling multiple nested keys with same name",

0 commit comments

Comments
 (0)