mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
fix(toml/parse): fix edge cases (#3509)
This commit is contained in:
parent
5be01a0931
commit
3830a00aee
@ -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, ","),
|
||||
|
@ -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"));
|
||||
|
2
toml/testdata/arrays.toml
vendored
2
toml/testdata/arrays.toml
vendored
@ -8,3 +8,5 @@ hosts = [
|
||||
] # comment
|
||||
|
||||
profiles = [ { name = "John", "john@example.com" = true }, { name = "Doe", "doe@example.com" = true }, ]
|
||||
|
||||
floats = [ 0.1, -1.25 ]
|
1
toml/testdata/inlineTable.toml
vendored
1
toml/testdata/inlineTable.toml
vendored
@ -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 = {}
|
||||
|
Loading…
Reference in New Issue
Block a user