fix(muya): escape braces in a plain-text find query by Dev-next-gen · Pull Request #5428 · marktext/marktext · GitHub
Skip to content

fix(muya): escape braces in a plain-text find query - #5428

Merged
Jocs merged 1 commit into
marktext:developfrom
Dev-next-gen:fix/literal-search-braces
Sep 17, 2026
Merged

Jocs merged 1 commit into
marktext:developfrom
Dev-next-gen:fix/literal-search-braces

Conversation

@Dev-next-gen

Copy link
Copy Markdown
Contributor

Fixes #5427

Summary

With the regexp option off, matchString in packages/muya/src/utils/search.ts escapes the query before building the RegExp, but its SPECIAL_CHAR_REG class left out { and }. A query like a{2} therefore became a quantifier: Find highlighted aa and never the text a{2}, and Replace rewrote the wrong text. This adds the two braces to the class. A lone { already worked, since it is literal outside Unicode mode, and escaping it gives the same result.

Regexp mode is unchanged: the escaping only runs when isRegexp is false.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added (or explain why not needed)
  • Manually tested on:

packages/muya/src/utils/__tests__/searchLiteralBraces.spec.ts covers a{2}, x{1,3}, a lone brace and the whole-word case. On develop (73b90a7), 4 of its 5 tests fail (expected [ [ +0, 'aa' ] ] to deeply equal [ [ 3, 'a{2}' ] ]); with the fix all 5 pass. npx vitest run src/utils/__tests__/ src/search passes the existing search suites too (61 tests), and eslint and tsc --noEmit on muya are clean. I did not try it in the desktop app.

Notes for reviewers [optional]

quickOpen.ts in the desktop package builds its file-name RegExp with a similar class that also omits the braces; I left it alone to keep this PR to the editor's Find.


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.

With the regexp option off, matchString escapes the query's regexp
characters but not { and }, so a query like a{2} became a quantifier:
it matched "aa" and never the text a{2}.
@Jocs
Jocs merged commit dbe6ab5 into marktext:develop Sep 17, 2026
7 checks passed
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.

[Bug] Find with the regexp option off treats { and } in the query as a quantifier

2 participants