Explicitly check the parser for errors on peek
It's curious choice from the underlying API to generally return a
positive result on success, but on this case return true in an error
scenario.
Fixes #666
diff --git a/decode.go b/decode.go
index c59dea4..0173b69 100644
--- a/decode.go
+++ b/decode.go
@@ -100,7 +100,10 @@
if p.event.typ != yaml_NO_EVENT {
return p.event.typ
}
- if !yaml_parser_parse(&p.parser, &p.event) {
+ // It's curious choice from the underlying API to generally return a
+ // positive result on success, but on this case return true in an error
+ // scenario. This was the source of bugs in the past (issue #666).
+ if !yaml_parser_parse(&p.parser, &p.event) || p.parser.error != yaml_NO_ERROR {
p.fail()
}
return p.event.typ
diff --git a/decode_test.go b/decode_test.go
index 5f65e43..72a8e46 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -947,6 +947,7 @@
{"%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: 1\nb: 2\nc 2\nd: 3\n", "^yaml: line 3: could not find expected ':'$"},
+ {"0: [:!00 \xef", "yaml: incomplete UTF-8 octet sequence"}, // Issue #666
{
"a: &a [00,00,00,00,00,00,00,00,00]\n" +
"b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]\n" +