Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode: prevent comments that look like dates to be accepted #657

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,6 @@ func (p *parser) parseSimpleKey(b []byte) (raw, key, rest []byte, err error) {
// simple-key = quoted-key / unquoted-key
// unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _
// quoted-key = basic-string / literal-string
if len(b) == 0 {
return nil, nil, nil, newDecodeError(b, "key is incomplete")
}

switch {
case b[0] == '\'':
return p.parseLiteralString(b)
Expand Down Expand Up @@ -884,6 +880,8 @@ func (p *parser) parseIntOrFloatOrDateTime(b []byte) (ast.Reference, []byte, err
if idx == 2 && c == ':' || (idx == 4 && c == '-') {
return p.scanDateTime(b)
}

break
}

return p.scanIntOrFloat(b)
Expand Down
24 changes: 24 additions & 0 deletions unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,30 @@ B = "data"`,
}
},
},
{
desc: "comment that looks like a date",
input: "a=19#9-",
gen: func() test {
doc := map[string]interface{}{}

return test{
target: &doc,
expected: &map[string]interface{}{"a": int64(19)},
}
},
},
{
desc: "comment that looks like a date",
input: "a=199#-",
gen: func() test {
doc := map[string]interface{}{}

return test{
target: &doc,
expected: &map[string]interface{}{"a": int64(199)},
}
},
},
}

for _, e := range examples {
Expand Down