Sfoglia il codice sorgente

increment non-zero scanner error lines (#319)

Scanner errors are 0 indexed. Errors occuring on lines greater than 0, referenced the previous line in the error text.

Fixes #205.
Sebastian Vidrio 8 anni fa
parent
commit
e47eca576e
2 ha cambiato i file con 6 aggiunte e 0 eliminazioni
  1. 4 0
      decode.go
  2. 2 0
      decode_test.go

+ 4 - 0
decode.go

@@ -113,6 +113,10 @@ func (p *parser) fail() {
 	var line int
 	if p.parser.problem_mark.line != 0 {
 		line = p.parser.problem_mark.line
+		// Scanner errors don't iterate line before returning error
+		if p.parser.error == yaml_SCANNER_ERROR {
+			line++
+		}
 	} else if p.parser.context_mark.line != 0 {
 		line = p.parser.context_mark.line
 	}

+ 2 - 0
decode_test.go

@@ -825,6 +825,8 @@ var unmarshalErrorTests = []struct {
 	{"v: !!float 'error'", "yaml: cannot decode !!str `error` as a !!float"},
 	{"v: [A,", "yaml: line 1: did not find expected node content"},
 	{"v:\n- [A,", "yaml: line 2: did not find expected node content"},
+	{"a:\n- b: *,", "yaml: line 2: did not find expected alphabetic or numeric character"},
+	{"a:\n- {b: c, d:e},", "yaml: line 2: found unexpected ':'"},
 	{"a: *b\n", "yaml: unknown anchor 'b' referenced"},
 	{"a: &a\n  b: *a\n", "yaml: anchor 'a' value contains itself"},
 	{"value: -", "yaml: block sequence entries are not allowed in this context"},