diff --git a/decode_test.go b/decode_test.go index 7e0e1101..51f50709 100644 --- a/decode_test.go +++ b/decode_test.go @@ -946,6 +946,7 @@ var unmarshalErrorTests = []struct { {"{{.}}", `yaml: invalid map key: map\[string]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" + diff --git a/scannerc.go b/scannerc.go index 7c78d235..09673941 100644 --- a/scannerc.go +++ b/scannerc.go @@ -673,7 +673,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 } @@ -886,9 +888,9 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) (ok 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: @@ -902,14 +904,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 @@ -1372,7 +1374,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{