Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid parsing ridiculously long strings #489

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/bun-clickhouse.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ 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
- run: cd test/e2e && bun install
- name: Workflow Telemetry
uses: runforesight/[email protected]
if: github.event_name != 'pull_request'
Expand Down
32 changes: 32 additions & 0 deletions parser/bnf.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,36 @@ 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_${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 = []
}
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
2 changes: 1 addition & 1 deletion test/e2e
Submodule e2e updated from 83d70c to 85e344
Loading