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 #597 #599

Merged
merged 1 commit into from
Nov 13, 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
31 changes: 11 additions & 20 deletions parser/bnf.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,23 @@ compiler.ParseScript = function (script) {
const aqLiterals = []
let _script = script
let res = ''
let qsMatch = _script.match(/^([^"]*)("([^"\\]|\\.)*")?/)
const re = /^([^"`]*)("(([^"\\]|\\.)*)"|`(([^`\\]|\\.)*)`)?/
let qsMatch = _script.match(re)
while (qsMatch && qsMatch[0]) {
let repl = qsMatch[2] || ''
let repl = qsMatch[2] || qsMatch[4] || ''
if (repl.length > 512) {
qLiterals.push(repl)
repl = `"QL_${qLiterals.length - 1}"`
if (repl.startsWith('"')) {
qLiterals.push(repl)
repl = `"QL_${qLiterals.length - 1}"`
} else {
aqLiterals.push(repl)
repl = `\`AL_${aqLiterals.length - 1}\``
}
}
res = res + qsMatch[1] + repl
_script = _script.slice(qsMatch[0].length)
qsMatch = _script.match(/^([^"]*)("([^"\\]|\\.)*")?/)
qsMatch = _script.match(re)
}

_script = res
res = ''
qsMatch = _script.match(/^([^`]*)(`([^`\\]|\\.)*`)?/)
while (qsMatch && qsMatch[0]) {
let repl = qsMatch[2] || ''
if (repl.length > 512) {
aqLiterals.push(repl)
repl = `\`AL_${qLiterals.length - 1}\``
}
res = res + qsMatch[1] + repl
_script = _script.slice(qsMatch[0].length)
qsMatch = _script.match(/^([^`]*)(`([^`\\]|\\.)*`)?/)
}

const parsedScript = this._ParseScript(res)
if (!parsedScript) {
return parsedScript
Expand Down
8 changes: 5 additions & 3 deletions parser/registry/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ module.exports.querySelectorPostProcess = (query) => {
* @returns {string}
*/
module.exports.unquoteToken = (token) => {
let value = token.Child('quoted_str').value
value = `"${value.substr(1, value.length - 2)}"`
return JSON.parse(value)
const value = token.Child('quoted_str').value
if (value.startsWith('"')) {
return JSON.parse(value)
}
return value.substr(1, value.length - 2)
}

/**
Expand Down
Loading