From 31927e0755e2af250e702a37f8e751112472294c Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Fri, 3 Jul 2026 12:06:04 +0530 Subject: [PATCH 1/2] fix: preserve $ characters in interpolated error message values stripIndent() substitutes each interpolated value into its errTemplate placeholder with String.prototype.replace and a string replacement. Because the search argument is a literal placeholder (no capture groups), a value containing `$&`, `$\``, `$'` or `$$` was interpreted as a special replacement pattern and corrupted the rendered message. Such values are common, for example JSON-stringified data embedded in an error. Pass a replacer function so the value is inserted literally. --- packages/errors/src/stripIndent.ts | 5 ++++- packages/errors/test/stripIndent.spec.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/errors/src/stripIndent.ts b/packages/errors/src/stripIndent.ts index 886d04811f5..b9ff2a152e1 100644 --- a/packages/errors/src/stripIndent.ts +++ b/packages/errors/src/stripIndent.ts @@ -27,7 +27,10 @@ export const stripIndent = (strings: TemplateStringsArray, ...args: any[]): stri let result = strippedLines.join('\n').trimLeft() args.forEach((arg, i) => { - result = result.replace(`<<${i}>>`, `${arg}`) + // Use a replacer function so `$` sequences in the arg (`$&`, `$\``, `$'`, + // `$$`) are inserted literally rather than treated as special replacement + // patterns by String.prototype.replace. + result = result.replace(`<<${i}>>`, () => `${arg}`) }) return result diff --git a/packages/errors/test/stripIndent.spec.ts b/packages/errors/test/stripIndent.spec.ts index 9ba85ec4792..54fac45b3f9 100644 --- a/packages/errors/test/stripIndent.spec.ts +++ b/packages/errors/test/stripIndent.spec.ts @@ -35,4 +35,12 @@ Something went wrong. - b - c`.trimLeft()) }) + + it('inserts an argument containing $ replacement patterns verbatim', () => { + const arg = `a$&b$\`c$'d$$e$1f` + + const str = stripIndent`You passed: ${arg}` + + expect(str).toEqual(`You passed: ${arg}`) + }) }) From 25e3109dafac259bfaedf05e229ee4562c44435a Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Tue, 7 Jul 2026 22:08:10 +0530 Subject: [PATCH 2/2] chore: add changelog entry --- cli/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 0e0994d8834..66af04e0d90 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -16,6 +16,7 @@ - Fixed an issue where opening an unconfigured project from a git repository sub-directory (such as a monorepo package) skipped project setup. Additionally, the component testing setup wizard now reliably displays the auto-detected framework and bundler. Fixes [#27410](https://github.com/cypress-io/cypress/issues/27410) and [#29544](https://github.com/cypress-io/cypress/issues/29544). Fixed in [#34129](https://github.com/cypress-io/cypress/pull/34129) and [#34212](https://github.com/cypress-io/cypress/pull/34212). - Fixed an issue where interacting with an element inside a horizontally-scrollable container could scroll the element to the container's right edge, placing it underneath a right-floating `position: sticky` or `position: fixed` element and causing the action to fail or land on the wrong element. Elements are now scrolled to their top, leftmost point as documented. Fixes [#33884](https://github.com/cypress-io/cypress/issues/33884). Fixed in [#34108](https://github.com/cypress-io/cypress/pull/34108). - Fixed a regression in [15.17.0](#15-17-0) where `cypress run --spec` printed a spurious `The following --spec pattern did not match any spec files and will be ignored` warning for patterns that actually did match spec files, such as patterns using regex-style alternation groups (for example `cypress/e2e/(a|b)/*.js`). Fixes [#34160](https://github.com/cypress-io/cypress/issues/34160). +- Fixed an issue where a Cypress error message that interpolated a value containing a `$` sequence (such as `$&`, `` $` ``, `$'`, or `$$`, for example JSON-stringified data shown in a configuration validation error) could render with corrupted or duplicated text. Such values are now shown verbatim. Fixed in [#34220](https://github.com/cypress-io/cypress/pull/34220). **Dependency Updates:**