-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(toml): parse()
duplicates the character next to reserved escape sequences
#4192
Conversation
@babiabeo |
I think we should stick to the spec and throw. |
Currently, this PR solves the issue by ignoring reserved escape sequences. However, I saw that most TOML parser packages throw an error in this case import { load } from "npm:js-toml";
console.log(load('a = "a\\0b"'));
// error: Uncaught (in promise) SyntaxParseError: Syntax error
// unexpected character: ->"<- at offset: 4, skipped 3 characters.
// unexpected character: ->b<- at offset: 8, skipped 2 characters. import tomllib
print(tomllib.loads('a = "a\\0b"'))
# File "D:\coding\programming\languages\python\Lib\tomllib\_parser.py", line 494, in parse_basic_str_escape
# raise suffixed_err(src, pos, "Unescaped '\\' in a string") from None
# tomllib.TOMLDecodeError: Unescaped '\' in a string (at line 1, column 9) package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type Data struct {
A string `toml:"a"`
}
func main() {
var data Data
_, err := toml.Decode("a = \"a\\0b\"", &data)
fmt.Println(err)
// toml: line 1 (last key "a"): invalid escape in string '\0'
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it best if we instead threw instead of ignoring, as to follow the spec. Are you able to rework this PR to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@babiabeo, I've made some tweaks to improve the thrown error message and accuracy of the tests. Do these changes seem reasonable to you?
Yes. I forgot to add |
parse
duplicates the character next to reserved escape sequencesparse()
duplicates the character next to reserved escape sequences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you, David.
Fix: #4187