mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 23:59:59 -05:00
fix(std): Parsing inline arrays of inline tables in toml (#7902)
This commit is contained in:
parent
fa80649926
commit
08f3ae92d3
3 changed files with 37 additions and 1 deletions
8
std/encoding/testdata/inlineArrayOfInlineTable.toml
vendored
Normal file
8
std/encoding/testdata/inlineArrayOfInlineTable.toml
vendored
Normal 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 } ]
|
|
@ -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))) {
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue