Skip to content

fix: Variables Editor client script fails to parse, blanking the whole UI - #228

Merged
sergak01 merged 1 commit into
developfrom
pp-3990
Aug 7, 2026
Merged

fix: Variables Editor client script fails to parse, blanking the whole UI#228
sergak01 merged 1 commit into
developfrom
pp-3990

Conversation

@sergak01

@sergak01 sergak01 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

escapeJsAttr() (added in #227's XSS fix) lives inside the single giant template literal that getVariablesEditorHtml() returns as the page's inline <script>. Its backslash-escaping regexes were correct for a standalone file, but the outer template literal consumes one level of backslash-escaping when the .ts source itself is parsed — so the browser received a syntactically broken script:

Invalid regular expression: /\/g, '\').replace(/: Unmatched ')'

That SyntaxError aborted the entire inline script, so neither the Schema nor the Values tab ever rendered — reproduced live against http://localhost:3000/@pp-dev/variables-editor in a consumer project (task-console) running @metricinsights/pp-dev@1.2.0.

Key changes

  • Doubled the escaping in escapeJsAttr() to compensate for the extra template-literal unescape pass — verified against the exact embedded-string pipeline with a standalone Node repro before touching the real file.
  • Added a regression test (tests/unit/lib/variables-editor.spec.ts) that extracts every <script> block from the rendered page and parses it with new Function(). Confirmed it fails on the pre-fix code and passes after the fix.

Testing

  • npx tsc --noEmit — clean
  • npm run lint — clean
  • npm run test:unit — 275/275 passing
  • Live verification: built + packed pp-dev locally, installed into task-console (npm install <tarball> --no-save), restarted its dev server, confirmed the Variables Editor now renders both tabs with no console errors on the exact tags: [] file that reproduced the bug.

Merge Request: origin/pp-3990origin/develop

…e UI

escapeJsAttr() lives inside the one giant template literal that
getVariablesEditorHtml() returns as the page's inline <script>. Its
backslash-escaping regexes were written for a standalone file, but the
outer template literal consumes one level of backslash-escaping when the
.ts source is parsed — so the browser received a syntactically broken
script (Invalid regular expression: /\/g, '\').replace(/: Unmatched ')').
The resulting SyntaxError aborted the entire inline script, so neither the
Schema nor the Values tab ever rendered, regardless of whether the schema
had any tags.

Doubles the escaping to compensate for the extra template-literal layer,
verified against the exact embedded-string pipeline. Adds a regression
test that extracts every <script> block from the rendered page and parses
it with `new Function()`, which fails on the old code and passes on the fix.
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8bdef91d-f8b8-4fc6-ba9d-18a7ddadd16c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sergak01 sergak01 self-assigned this Aug 7, 2026
@sergak01
sergak01 merged commit f16465f into develop Aug 7, 2026
3 checks passed
@sergak01
sergak01 deleted the pp-3990 branch August 7, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant