Skip to content

Commit

Permalink
Fix parsing of tab characters (#592)
Browse files Browse the repository at this point in the history
* fix parsing of tab characters

* fix parsing of tab indent in double-quote

* fix parsing of tab indent in single quote
  • Loading branch information
goccy authored Dec 14, 2024
1 parent 68f0bb5 commit a37e684
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
30 changes: 28 additions & 2 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,17 @@ func (s *Scanner) scanSingleQuote(ctx *Context) (*token.Token, error) {
}
}
continue
} else if isFirstLineChar && (c == ' ' || c == '\t') {
} else if isFirstLineChar && c == ' ' {
continue
} else if isFirstLineChar && c == '\t' {
if s.lastDelimColumn >= s.column {
return nil, ErrInvalidToken(
token.Invalid(
"tab character cannot be used for indentation in single-quoted text",
string(ctx.obuf), s.pos(),
),
)
}
continue
} else if c != '\'' {
value = append(value, c)
Expand Down Expand Up @@ -338,7 +348,17 @@ func (s *Scanner) scanDoubleQuote(ctx *Context) (*token.Token, error) {
}
}
continue
} else if isFirstLineChar && (c == ' ' || c == '\t') {
} else if isFirstLineChar && c == ' ' {
continue
} else if isFirstLineChar && c == '\t' {
if s.lastDelimColumn >= s.column {
return nil, ErrInvalidToken(
token.Invalid(
"tab character cannot be used for indentation in double-quoted text",
string(ctx.obuf), s.pos(),
),
)
}
continue
} else if c == '\\' {
isFirstLineChar = false
Expand Down Expand Up @@ -1413,6 +1433,12 @@ func (s *Scanner) scan(ctx *Context) error {
s.progressColumn(ctx, 1)
continue
}
if s.lastDelimColumn < s.column {
s.indentNum++
ctx.addOriginBuf(c)
s.progressColumn(ctx, 1)
continue
}
if err := s.scanTab(ctx, c); err != nil {
return err
}
Expand Down
10 changes: 0 additions & 10 deletions yaml_test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ var failureTestNames = []string{
"various-trailing-comments-1-3", // no json.
"zero-indented-sequences-in-explicit-mapping-keys", // no json.

"legal-tab-after-indentation", // pass yamlv3.
"multiline-plain-value-with-tabs-on-empty-lines", // pass yamlv3.
"tabs-that-look-like-indentation/05", // pass yamlv3.

"colon-at-the-beginning-of-adjacent-flow-scalar",
"comment-without-whitespace-after-doublequoted-scalar",
"construct-binary",
Expand All @@ -61,14 +57,8 @@ var failureTestNames = []string{
"spec-example-9-3-bare-documents",
"spec-example-9-6-stream",
"spec-example-9-6-stream-1-3",
"tab-at-beginning-of-line-followed-by-a-flow-mapping",
"tab-indented-top-flow",
"tabs-in-various-contexts/003",
"tabs-that-look-like-indentation/00",
"tabs-that-look-like-indentation/01",
"tabs-that-look-like-indentation/03",
"tabs-that-look-like-indentation/04",
"tabs-that-look-like-indentation/07",
"tag-shorthand-used-in-documents-but-only-defined-in-the-first",
"trailing-line-of-spaces/01", // last '\n' character is needed ?
"wrong-indented-flow-sequence", // error ?
Expand Down

0 comments on commit a37e684

Please sign in to comment.