Skip to content

Commit

Permalink
fix invalid escape character
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Nov 29, 2024
1 parent 76e669a commit 352b034
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ func TestDecoder(t *testing.T) {
},
{
"a: \"\\0\"\n",
map[string]string{"a": "\\0"},
map[string]string{"a": "\x00"},
},
{
"b: 2\na: 1\nd: 4\nc: 3\nsub:\n e: 5\n",
Expand Down
2 changes: 1 addition & 1 deletion lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ t4: 2098-01-09T10:40:47Z
Type: token.DoubleQuoteType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.QuotedScalarIndicator,
Value: "\\0",
Value: "\x00",
Origin: " \"\\0\"",
},
},
Expand Down
12 changes: 11 additions & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,20 @@ func (s *Scanner) scanDoubleQuote(ctx *Context) (*token.Token, error) {
progress = 1
ctx.addOriginBuf(nextChar)
value = append(value, nextChar)
case '0':
progress = 1
ctx.addOriginBuf(nextChar)
value = append(value, '\x00')
case ' ':
// skip escape character.
default:
value = append(value, c)
s.progressColumn(ctx, 1)
return nil, ErrInvalidToken(
token.Invalid(
fmt.Sprintf("found unknown escape character %q", nextChar),
string(ctx.obuf), s.pos(),
),
)
}
idx += progress
s.progressColumn(ctx, progress)
Expand Down
1 change: 0 additions & 1 deletion yaml_test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ var failureTestNames = []string{
"implicit-flow-mapping-key-on-one-line", // no json.
"invalid-comment-after-comma",
"invalid-comment-after-end-of-flow-sequence",
"invalid-escape-in-double-quoted-string",
"invalid-tag",
"key-with-anchor-after-missing-explicit-mapping-value",
"leading-tabs-in-double-quoted/02",
Expand Down

0 comments on commit 352b034

Please sign in to comment.