fix(toml/parse): fix edge cases (#3509)

This commit is contained in:
Brian Knight 2023-07-30 05:23:34 -04:00 committed by GitHub
parent 5be01a0931
commit 3830a00aee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 1 deletions

View File

@ -354,7 +354,7 @@ function character(str: string) {
const Patterns = {
BARE_KEY: /[A-Za-z0-9_-]/,
FLOAT: /[0-9_\.e+\-]/i,
END_OF_VALUE: /[ \t\r\n#,}]/,
END_OF_VALUE: /[ \t\r\n#,}\]]/,
};
export function BareKey(scanner: Scanner): ParseResult<string> {
@ -741,6 +741,10 @@ export function InlineTable(
scanner: Scanner,
): ParseResult<Record<string, unknown>> {
scanner.nextUntilChar();
if (scanner.char(1) === "}") {
scanner.next(2);
return success({});
}
const pairs = surround(
"{",
join(Pair, ","),

View File

@ -132,6 +132,10 @@ Deno.test({
["gamma", "delta"],
[1, 2],
],
floats: [
0.1,
-1.25,
],
hosts: ["alpha", "omega"],
profiles: [
{
@ -297,6 +301,7 @@ Deno.test({
],
},
},
empty: {},
},
};
const actual = parseFile(path.join(testdataDir, "inlineTable.toml"));

View File

@ -8,3 +8,5 @@ hosts = [
] # comment
profiles = [ { name = "John", "john@example.com" = true }, { name = "Doe", "doe@example.com" = true }, ]
floats = [ 0.1, -1.25 ]

View File

@ -8,3 +8,4 @@ nile = { derek.roddy = "drummer", also = { malevolant.creation = { drum.kit = "T
annotation_filter = { "kubernetes.io/ingress.class" = "nginx" }
literal_key = { 'foo\nbar' = 'foo\nbar' }
nested = { parent = { children = ["{", "}"], "child.ren" = ["[", "]"] } } # comment
empty = {}