Skip to content

Conversation

@HugoHSun
Copy link
Contributor

@HugoHSun HugoHSun commented Dec 23, 2025

  • before: {user. matches user + any character
  • after: {user\. matches user + literal dot
  • add test cases
image
🚥 Resolves CX-2232

🧰 Changes

The Bug:
The regex /\{user.(...)/ had an unescaped . after user, which matches any character instead of a literal dot. This caused patterns like {userEndpoint} to incorrectly match as a ReadMe variable, where the . matched E and captured ndpoint.

Symptoms:

  • ${userEndpoint} rendered as $NDPOINT
  • ${userXYZ} rendered as $YZ
  • Only visible in SuperHub View mode (syntax highlighter runs client-side with tokenizeVariables: true)

The Fix:
Escape the dot to match only a literal . character:

  • Before: {user. → matches user + any character
  • After: {user\. → matches user + literal dot only

Added test cases to ensure the regex does not match JS template literal patterns without an actual dot after user.

🧬 QA & Testing

  1. Create a doc with a code block containing JS template literals:
    const url = ${baseUrl}/${userEndpoint}/login;
    const ok = ${userXYZ};

  2. Save and view the page (both Edit preview and public View)

  3. Expected: Code renders verbatim - ${userEndpoint} and ${userXYZ} appear exactly as written

  4. Before fix: Variables were mangled - ${userEndpoint}$NDPOINT, ${userXYZ}$YZ

  5. Run unit tests: npm test in the variable package

- before: `{user.` matches user + any character
- after: `{user\.` matches user + literal dot
- add test cases
@HugoHSun HugoHSun changed the title fix(mdx-variable-regex): escape . after user fix(mdx-variable-regex): user variable display in SuperHub read mode Dec 23, 2025
@HugoHSun HugoHSun force-pushed the hugo/cx-2232-code-blocks-mangle-var-tokens-drops-braces-substrings branch from 6e46b8b to 0a7a204 Compare December 23, 2025 02:53
@HugoHSun HugoHSun marked this pull request as ready for review December 23, 2025 03:49
@HugoHSun HugoHSun requested a review from erunion as a code owner December 23, 2025 03:49
@HugoHSun HugoHSun force-pushed the hugo/cx-2232-code-blocks-mangle-var-tokens-drops-braces-substrings branch from 91e0fb6 to 8a458af Compare December 23, 2025 04:09
@erunion
Copy link
Member

erunion commented Dec 23, 2025

ill publish this tomorrow morning

@erunion erunion merged commit 21094b8 into main Dec 23, 2025
5 checks passed
@erunion erunion deleted the hugo/cx-2232-code-blocks-mangle-var-tokens-drops-braces-substrings branch December 23, 2025 04:13
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.

3 participants