From cf133c8945ea6787fc4cfb5b46bbd3ad1d0e644a Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 5 Apr 2024 11:45:46 +0300 Subject: [PATCH 1/5] fix: avoid parsing ridiculously long strings --- parser/bnf.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/parser/bnf.js b/parser/bnf.js index 531d4817..50ce5c71 100644 --- a/parser/bnf.js +++ b/parser/bnf.js @@ -70,4 +70,33 @@ for (const [name, rule] of Object.entries(compiler.languages.logql.rules)) { } } +compiler._ParseScript = compiler.ParseScript +/** + * hack to avoid ridiculously long strings + * @param script {string} + * @constructor + */ +compiler.ParseScript = function (script) { + const qLiterals = [] + const aqLiterals = [] + const quotedStrings = script.replaceAll(/"([^"\\]|\\.)+"/g, (str) => { + qLiterals.push(str) + return `"QL_${qLiterals.length - 1}"` + }) + const aQuotedStrings = quotedStrings.replaceAll(/`([^`\\]|\\.)+`/g, (str) => { + aqLiterals.push(str) + return `\`AL_${qLiterals.length - 1}\`` + }) + const parsedScript = this._ParseScript(aQuotedStrings) + for (const t of parsedScript.rootToken.Children('QLITERAL')) { + t._value = qLiterals[parseInt(t.value.slice(4, t.value.length - 1))] + t.tokens = [] + } + for (const t of parsedScript.rootToken.Children('AQLITERAL')) { + t._value = aqLiterals[parseInt(t.value.slice(4, t.value.length - 1))] + t.tokens = [] + } + return parsedScript +} + module.exports = compiler From 0733e7ce14e95f74ad9453d784725c13210cff52 Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 5 Apr 2024 13:17:02 +0300 Subject: [PATCH 2/5] fix: debug --- parser/bnf.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/parser/bnf.js b/parser/bnf.js index 50ce5c71..b3dde280 100644 --- a/parser/bnf.js +++ b/parser/bnf.js @@ -85,9 +85,12 @@ compiler.ParseScript = function (script) { }) const aQuotedStrings = quotedStrings.replaceAll(/`([^`\\]|\\.)+`/g, (str) => { aqLiterals.push(str) - return `\`AL_${qLiterals.length - 1}\`` + return `\`AL_${aqLiterals.length - 1}\`` }) const parsedScript = this._ParseScript(aQuotedStrings) + if (!parsedScript) { + return parsedScript + } for (const t of parsedScript.rootToken.Children('QLITERAL')) { t._value = qLiterals[parseInt(t.value.slice(4, t.value.length - 1))] t.tokens = [] From a890f2f3b959f975e07dac370ae95263cbcf81e1 Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 5 Apr 2024 13:38:13 +0300 Subject: [PATCH 3/5] update e2e --- test/e2e | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e b/test/e2e index 83d70c90..a29b7423 160000 --- a/test/e2e +++ b/test/e2e @@ -1 +1 @@ -Subproject commit 83d70c90e75ba3c80315ac1a4563f2e223159da1 +Subproject commit a29b742376975e1d299e3b6f1aa014990798484c From 9dbc5c8fe73f51e30abe1e656bc6f51703abe64d Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 5 Apr 2024 14:03:08 +0300 Subject: [PATCH 4/5] fix: bun install after module update --- .github/workflows/bun-clickhouse.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bun-clickhouse.js.yml b/.github/workflows/bun-clickhouse.js.yml index 428190e5..7ca1c606 100644 --- a/.github/workflows/bun-clickhouse.js.yml +++ b/.github/workflows/bun-clickhouse.js.yml @@ -39,9 +39,9 @@ jobs: with: bun-version: ${{ matrix.bun-version }} - run: rm -rf package-lock.json - - run: bun install - run: git submodule init - run: git submodule update + - run: bun install - name: Workflow Telemetry uses: runforesight/workflow-telemetry-action@v1.8.7 if: github.event_name != 'pull_request' From a785967d19a29324b3ff3450ebdfc58bae4b0585 Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 5 Apr 2024 14:21:07 +0300 Subject: [PATCH 5/5] fix: install deps --- .github/workflows/bun-clickhouse.js.yml | 1 + test/e2e | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bun-clickhouse.js.yml b/.github/workflows/bun-clickhouse.js.yml index 7ca1c606..1f3da331 100644 --- a/.github/workflows/bun-clickhouse.js.yml +++ b/.github/workflows/bun-clickhouse.js.yml @@ -42,6 +42,7 @@ jobs: - run: git submodule init - run: git submodule update - run: bun install + - run: cd test/e2e && bun install - name: Workflow Telemetry uses: runforesight/workflow-telemetry-action@v1.8.7 if: github.event_name != 'pull_request' diff --git a/test/e2e b/test/e2e index a29b7423..85e344c8 160000 --- a/test/e2e +++ b/test/e2e @@ -1 +1 @@ -Subproject commit a29b742376975e1d299e3b6f1aa014990798484c +Subproject commit 85e344c83efb747b123758212e216f9f6a355da2