1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 16:19:12 -05:00

fix(std): Parsing inline arrays of inline tables in toml (#7902)

This commit is contained in:
Peter 2020-10-11 21:33:23 +02:00 committed by GitHub
parent fa80649926
commit 08f3ae92d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 1 deletions

View file

@ -0,0 +1,8 @@
[inlineArray]
string = [ {var = "a string"} ]
my_points = [ { x = 1, y = 2, z = 3 }, { x = 7, y = 8, z = 9 }, { x = 2, y = 4, z = 8 } ]
points = [ { x = 1, y = 2, z = 3 },
{ x = 7, y = 8, z = 9 },
{ x = 2, y = 4, z = 8 } ]

View file

@ -305,7 +305,10 @@ class Parser {
dataString = dataString.replace(/,]/g, "]");
}
if (dataString[0] === "{" && dataString[dataString.length - 1] === "}") {
if (
(dataString[0] === "{" && dataString[dataString.length - 1] === "}") ||
(dataString[0] === "[" && dataString[dataString.length - 1] === "]")
) {
const reg = /([a-zA-Z0-9-_\.]*) (=)/gi;
let result;
while ((result = reg.exec(dataString))) {

View file

@ -441,3 +441,28 @@ Deno.test({
assertEquals(actual, expected);
},
});
Deno.test({
name: "[TOML] Inline Array of Inline Table",
fn(): void {
const expected = {
inlineArray: {
string: [{ var: "a string" }],
my_points: [
{ x: 1, y: 2, z: 3 },
{ x: 7, y: 8, z: 9 },
{ x: 2, y: 4, z: 8 },
],
points: [
{ x: 1, y: 2, z: 3 },
{ x: 7, y: 8, z: 9 },
{ x: 2, y: 4, z: 8 },
],
},
};
const actual = parseFile(
path.join(testdataDir, "inlineArrayOfInlineTable.toml"),
);
assertEquals(actual, expected);
},
});