Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions scannerc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Loading