From d615ebefe2e306f2877afb40dc603f71263407d6 Mon Sep 17 00:00:00 2001 From: Jarrett Helton Date: Mon, 3 Aug 2020 13:26:02 -0400 Subject: [PATCH] fix(std/toml): parser error with inline comments (#6942) --- std/encoding/testdata/boolean.toml | 3 ++- std/encoding/toml.ts | 2 +- std/encoding/toml_test.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/std/encoding/testdata/boolean.toml b/std/encoding/testdata/boolean.toml index 242d29c969..e3e287981b 100644 --- a/std/encoding/testdata/boolean.toml +++ b/std/encoding/testdata/boolean.toml @@ -1,3 +1,4 @@ [boolean] # i hate comments bool1 = true -bool2 = false \ No newline at end of file +bool2 = false +bool3 = true # I love comments \ No newline at end of file diff --git a/std/encoding/toml.ts b/std/encoding/toml.ts index 43788c06ac..336af97fb2 100644 --- a/std/encoding/toml.ts +++ b/std/encoding/toml.ts @@ -280,7 +280,7 @@ class Parser { return dataString.slice(0, endOfString); } - const m = /(?:|\[|{|).*(?:|\]||})\s*[^#]/g.exec(dataString); + const m = /(?:|\[|{).*(?:|\]|})\s*^((?!#).)*/g.exec(dataString); if (m) { return m[0].trim(); } else { diff --git a/std/encoding/toml_test.ts b/std/encoding/toml_test.ts index 45d0a66e64..0a927cde9d 100644 --- a/std/encoding/toml_test.ts +++ b/std/encoding/toml_test.ts @@ -48,7 +48,7 @@ Deno.test({ Deno.test({ name: "[TOML] Boolean", fn(): void { - const expected = { boolean: { bool1: true, bool2: false } }; + const expected = { boolean: { bool1: true, bool2: false, bool3: true } }; const actual = parseFile(path.join(testFilesDir, "boolean.toml")); assertEquals(actual, expected); },