Skip to content

UID2-7159: fix highlightJSON rendering spurious space in link_id values with colons#646

Open
sunnywu wants to merge 1 commit into
mainfrom
syw-UID2-7159-fix-highlight-json-colons
Open

UID2-7159: fix highlightJSON rendering spurious space in link_id values with colons#646
sunnywu wants to merge 1 commit into
mainfrom
syw-UID2-7159-fix-highlight-json-colons

Conversation

@sunnywu
Copy link
Copy Markdown
Contributor

@sunnywu sunnywu commented May 25, 2026

Summary

  • Root cause: highlightJSON in webroot/js/component/output.js used five sequential .replace() calls. Each later pass re-processed content already inside <span> tags from earlier passes. Colons inside string values (e.g. azure:eastus2:71ad8e1e-...) caused the step-3 number regex (/:\s*(\d+)/g) to match :71 inside the UUID and inject a hardcoded : prefix, producing a spurious visual space on the service-link admin page.
  • Fix: Replace all five chained regex calls with a single-pass tokeniser regex that matches quoted strings (with escape-sequence support), keywords, and numbers in one pass. String content is never re-examined, so embedded colons are harmless.
  • Tests: Added a Jest test suite (webroot/js/component/__tests__/output.test.mjs, 17 tests) covering the regression case and all value types.

Test Plan

  • npm test in webroot/ — 17 tests pass
  • Regression case: link_id: "azure:eastus2:71ad8e1e-..." renders without spurious space
  • All value types highlighted correctly: keys, string values, numbers, booleans, null, array elements
  • Strings containing true/false/numbers are not incorrectly highlighted as booleans/numbers

Jira

UID2-7159

🤖 Generated with Claude Code

…es with colons

Replace the chained-regex approach in highlightJSON with a single-pass
tokeniser regex. The previous implementation applied five sequential
.replace() calls to the same string; each later pass could re-process
content already inside <span> tags inserted by an earlier pass. Colons
inside string values (e.g. "azure:eastus2:uuid") caused the number regex
to match ":71" and inject a hardcoded ": " prefix, producing a spurious
visual space in the service-link admin page output.

The new single regex matches quoted strings (with escape-sequence support),
keywords, and numbers in one pass, so string content is never re-examined.

Adds a Jest test suite (17 tests) covering the regression case and all
value types (keys, strings with embedded colons, numbers, booleans, null,
array elements, pre-serialised JSON strings).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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