Skip to content

fix: consistent and likely safer regex escaping#1439

Merged
ghostdevv merged 7 commits intomainfrom
gd/regex-escape
Apr 5, 2026
Merged

fix: consistent and likely safer regex escaping#1439
ghostdevv merged 7 commits intomainfrom
gd/regex-escape

Conversation

@ghostdevv
Copy link
Copy Markdown
Contributor

@ghostdevv ghostdevv commented Feb 12, 2026

Replaces random regex escaping with @li/regexp-escape-polyfill, a spec-compliant polyfill for RegExp.escape(). I searched for every RegExp call, and replaced the ones that needed them. Most didn't use any dynamic strings, but the couple that did are updated here or didn't need it

@ghostdevv ghostdevv requested a review from danielroe February 12, 2026 18:28
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Apr 5, 2026 3:54am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Apr 5, 2026 3:54am
npmx-lunaria Ignored Ignored Apr 5, 2026 3:54am

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

Adds a TypeScript global augmentation declaring RegExp.escape(str: string) in global.d.ts and includes that file in Nuxt TypeScript config. Replaces direct interpolation into regexes with RegExp.escape(...) in useMarkdown.ts, useStructuredFilters.ts and shared/utils/emoji.ts. Also adds global.d.ts to knip's ignore list. No runtime logic changes beyond using escaped strings when building regular expressions.

Suggested reviewers

  • danielroe
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description accurately describes the changeset, explaining the migration to RegExp.escape() polyfill and documenting the scope of changes across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch gd/regex-escape

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 and usage tips.

Copy link
Copy Markdown
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that the benefit is worth the cost in terms of browser compatibility.

wdyt @ghostdevv?

@ghostdevv
Copy link
Copy Markdown
Contributor Author

ghostdevv commented Feb 12, 2026

I'm not sure that the benefit is worth the cost in terms of browser compatibility.

yeaaa maybe, perhaps there is a minimal ponyfill that achieves the same result 🤔 (because we need something for this, and I'd like to avoid having multiple fns for it over the codebase)

@ghostdevv
Copy link
Copy Markdown
Contributor Author

ghostdevv commented Feb 12, 2026

some initial findings, need to step away for a bit so will take another look later

@wojtekmaj
Copy link
Copy Markdown
Contributor

I'm not sure that the benefit is worth the cost in terms of browser compatibility.

wdyt @ghostdevv?

On the other hand, I don't think a large percentage of npmx audience is using IE or is 11 Chrome versions behind.

@danielroe
Copy link
Copy Markdown
Member

regexp.escape won't work on iOS 17 devices. I agree we need a canonical single escape function but it's a tiny one-liner, for our purposes. (https://github.com/lionel-rowe/regexp-escape-polyfill (linked by @ghostdevv above) is just 498 B)

@ghostdevv
Copy link
Copy Markdown
Contributor Author

updated to use @li/regexp-escape-polyfill

@ghostdevv
Copy link
Copy Markdown
Contributor Author

For some reason the vercel preview is crashing when you access a package page directly 🤔 it doesn't happen in dev or local preview

@43081j
Copy link
Copy Markdown
Contributor

43081j commented Feb 24, 2026

i caught up from main, and the preview seems to work now too FYI

# Conflicts:
#	app/composables/useMarkdown.ts
#	app/composables/useStructuredFilters.ts
#	package.json
#	pnpm-lock.yaml
@ghostdevv ghostdevv marked this pull request as ready for review April 5, 2026 03:54
@ghostdevv ghostdevv requested a review from wojtekmaj April 5, 2026 03:54
@ghostdevv ghostdevv requested review from 43081j and removed request for wojtekmaj April 5, 2026 03:54
@ghostdevv ghostdevv changed the title fix: use regexp.escape fix: consistent and likely safer regex escaping Apr 5, 2026
@ghostdevv ghostdevv added this pull request to the merge queue Apr 5, 2026
Merged via the queue into main with commit 42fc173 Apr 5, 2026
25 checks passed
@ghostdevv ghostdevv deleted the gd/regex-escape branch April 5, 2026 21: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.

4 participants