mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
fix(std/encoding/toml): Stop TOML parser from detecting numbers in strings. (#7064)
Before this patch the TOML parser would incorrect treat the string "base64data0xdamaged" in a declaration as a hex number because the corresponding check triggers even when the "0x" is inside a double quoted string literal as long as it is followed by at least one hex character.
This commit is contained in:
parent
95a6812e82
commit
93e2bfe22e
3 changed files with 4 additions and 1 deletions
1
std/encoding/testdata/string.toml
vendored
1
std/encoding/testdata/string.toml
vendored
|
@ -31,3 +31,4 @@ trimmed in raw strings.
|
|||
|
||||
withApostrophe = "What if it's not?"
|
||||
withSemicolon = "const message = 'hello world';"
|
||||
withHexNumberLiteral = "Prevent bug from stripping string here ->0xabcdef"
|
||||
|
|
|
@ -218,7 +218,7 @@ class Parser {
|
|||
}
|
||||
|
||||
// If binary / octal / hex
|
||||
const hex = /(0(?:x|o|b)[0-9a-f_]*)[^#]/gi.exec(dataString);
|
||||
const hex = /^(0(?:x|o|b)[0-9a-f_]*)[^#]/gi.exec(dataString);
|
||||
if (hex && hex[0]) {
|
||||
return hex[0].trim();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ Deno.test({
|
|||
"whitespace\n is preserved.",
|
||||
withApostrophe: "What if it's not?",
|
||||
withSemicolon: `const message = 'hello world';`,
|
||||
withHexNumberLiteral:
|
||||
"Prevent bug from stripping string here ->0xabcdef",
|
||||
},
|
||||
};
|
||||
const actual = parseFile(path.join(testFilesDir, "string.toml"));
|
||||
|
|
Loading…
Reference in a new issue