From 03a3256e9c62e38f2b35fa83c35be06fe2123fd2 Mon Sep 17 00:00:00 2001 From: Jakob Strobl Date: Fri, 28 Aug 2020 18:51:06 -0400 Subject: fix(std/encoding/toml): Comment after arrays causing incorrect output (#7224) --- std/encoding/toml.ts | 100 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 30 deletions(-) (limited to 'std/encoding/toml.ts') diff --git a/std/encoding/toml.ts b/std/encoding/toml.ts index 212c14bdc..62acc7db7 100644 --- a/std/encoding/toml.ts +++ b/std/encoding/toml.ts @@ -32,14 +32,82 @@ class Parser { for (let i = 0; i < this.tomlLines.length; i++) { const s = this.tomlLines[i]; const trimmed = s.trim(); - if (trimmed !== "" && trimmed[0] !== "#") { + if (trimmed !== "") { out.push(s); } } this.tomlLines = out; + this._removeComments(); this._mergeMultilines(); } + _removeComments(): void { + function isFullLineComment(line: string) { + return line.match(/^#/) ? true : false; + } + + function stringStart(line: string) { + const m = line.match(/(?:=\s*\[?\s*)("""|'''|"|')/); + if (!m) { + return false; + } + + // We want to know which syntax was used to open the string + openStringSyntax = m[1]; + return true; + } + + function stringEnd(line: string) { + // match the syntax used to open the string when searching for string close + // e.g. if we open with ''' we must close with a ''' + const reg = RegExp(`(?