Skip to content

Commit

Permalink
Ignore invalid escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
stirante committed Jul 13, 2023
1 parent 5b80f71 commit f15a3af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions jsonte/json/json_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,6 @@ func parseString(str *StringReader, p string) (string, error) {
result = append(result, '\\')
case TokenSlash:
result = append(result, '/')
case TokenAsterisk:
result = append(result, '*')
case 'b':
result = append(result, '\b')
case 'f':
Expand All @@ -708,7 +706,8 @@ func parseString(str *StringReader, p string) (string, error) {
}
result = append(result, []rune(string(rune(unicode)))...)
default:
return "", utils.WrappedJsonErrorf(p, "Invalid escape sequence at line %d, column %d", str.line, str.column)
result = append(result, '\\')
result = append(result, token)
}
} else {
result = append(result, token)
Expand Down
12 changes: 12 additions & 0 deletions test/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1583,3 +1583,15 @@ func TestParsingString(t *testing.T) {
}`
assertTemplate(t, template, expected)
}

func TestEscapeSingleQuote(t *testing.T) {
template := `{
"$template": {
"test": "{{[1,2,3].map(x => 'q.property(\'example:test\')')}}"
}
}`
expected := `{
"test": ["q.property('example:test')","q.property('example:test')","q.property('example:test')"]
}`
assertTemplate(t, template, expected)
}

0 comments on commit f15a3af

Please sign in to comment.