Skip to content

Commit

Permalink
Fix issue in simple_keys improvements (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Nov 19, 2019
1 parent a95acef commit 1f64d61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ var unmarshalErrorTests = []struct {
{"{{.}}", `yaml: invalid map key: map\[interface\ \{\}\]interface \{\}\{".":interface \{\}\(nil\)\}`},
{"b: *a\na: &a {c: 1}", `yaml: unknown anchor 'a' referenced`},
{"%TAG !%79! tag:yaml.org,2002:\n---\nv: !%79!int '1'", "yaml: did not find expected whitespace"},
{"a:\n 1:\nb\n 2:", ".*could not find expected ':'"},
{
"a: &a [00,00,00,00,00,00,00,00,00]\n" +
"b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]\n" +
Expand Down
19 changes: 12 additions & 7 deletions scannerc.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ func yaml_parser_fetch_more_tokens(parser *yaml_parser_t) bool {
if simple_key.token_number < parser.tokens_parsed {
break
}
if yaml_simple_key_is_valid(parser, simple_key) && simple_key.token_number == parser.tokens_parsed {
if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok {
return false
} else if valid && simple_key.token_number == parser.tokens_parsed {
need_more_tokens = true
break
}
Expand Down Expand Up @@ -831,9 +833,9 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool {
"found character that cannot start any token")
}

func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key_t) bool {
func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key_t) (valid, ok bool) {
if !simple_key.possible {
return false
return false, true
}

// The 1.2 specification says:
Expand All @@ -847,14 +849,14 @@ func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key
if simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index {
// Check if the potential simple key to be removed is required.
if simple_key.required {
return yaml_parser_set_scanner_error(parser,
return false, yaml_parser_set_scanner_error(parser,
"while scanning a simple key", simple_key.mark,
"could not find expected ':'")
}
simple_key.possible = false
return false
return false, true
}
return true
return true, true
}

// Check if a simple key may start at the current position and add it if
Expand Down Expand Up @@ -1286,7 +1288,10 @@ func yaml_parser_fetch_value(parser *yaml_parser_t) bool {
simple_key := &parser.simple_keys[len(parser.simple_keys)-1]

// Have we found a simple key?
if yaml_simple_key_is_valid(parser, simple_key) {
if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok {
return false

} else if valid {

// Create the KEY token and insert it into the queue.
token := yaml_token_t{
Expand Down

0 comments on commit 1f64d61

Please sign in to comment.