diff --git a/decode_test.go b/decode_test.go index 5f7326c1..94bc0250 100644 --- a/decode_test.go +++ b/decode_test.go @@ -250,6 +250,17 @@ var unmarshalTests = []struct { map[string]string{"scalar": "\nfolded line\nnext line\n * one\n * two\n\nlast line\n"}, }, + // Block scalar whose first line starts with a tab after the indentation: + // the tab is content (YAML 1.2.2 example 8.2). + { + "- |\n detected\n- >\n \n \n # detected\n- |1\n explicit\n- >\n \t\n detected\n", + []interface{}{"detected\n", "\n\n# detected\n", " explicit\n", "\t\ndetected\n"}, + }, + { + "a: |-\n \ttext\n", + map[string]string{"a": "\ttext"}, + }, + // Map inside interface with no type hints. { "a: {b: c}", @@ -1028,6 +1039,8 @@ var unmarshalErrorTests = []struct { {"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:\n b: |\n \ttext\n", "yaml: line 2: found a tab character where an indentation space is expected"}, + {"- |\n\ttext\n", "yaml: line 2: found a tab character where an indentation space is expected"}, {"a: 1\nb: 2\nc 2\nd: 3\n", "^yaml: line 3: could not find expected ':'$"}, {"#\n-\n{", "yaml: line 3: could not find expected ':'"}, // Issue #665 {"0: [:!00 \xef", "yaml: incomplete UTF-8 octet sequence"}, // Issue #666 diff --git a/scannerc.go b/scannerc.go index 7ee4f10e..c78c4b3e 100644 --- a/scannerc.go +++ b/scannerc.go @@ -2405,8 +2405,12 @@ func yaml_parser_scan_block_scalar_breaks(parser *yaml_parser_t, indent *int, br max_indent = parser.mark.column } - // Check for a tab character messing the indentation. - if (*indent == 0 || parser.mark.column < *indent) && is_tab(parser.buffer, parser.buffer_pos) { + // Check for a tab character messing the indentation. Before the + // indentation is detected, a tab after the required indentation + // prefix is content, not indentation (YAML 1.2.2 example 8.2). + if is_tab(parser.buffer, parser.buffer_pos) && + ((*indent == 0 && parser.mark.column <= parser.indent) || + (*indent > 0 && parser.mark.column < *indent)) { return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", start_mark, "found a tab character where an indentation space is expected") }