Visitar URL original
fix(linkifyjs): build Unicode regexes dynamically for ICU-free runtimes by aleclarson · Pull Request #572 · nfrasser/linkifyjs · GitHub
Skip to content

fix(linkifyjs): build Unicode regexes dynamically for ICU-free runtimes - #572

Open
aleclarson wants to merge 1 commit into
nfrasser:mainfrom
aleclarson:fix/icu-free-regexp-literals
Open

aleclarson wants to merge 1 commit into
nfrasser:mainfrom
aleclarson:fix/icu-free-regexp-literals

Conversation

@aleclarson

Copy link
Copy Markdown

Problem

packages/linkifyjs/src/regexp.mjs declares LETTER and EMOJI as /\p{L}/u and /\p{Emoji}/u regex literals at module scope. Embedded JS runtimes built without ICU — e.g. NativeScript's V8 — throw a SyntaxError at parse time for \p{} property escapes. The whole file fails to parse, so any bundled app importing linkifyjs (or a transitive importer like @tiptap/extension-link) dies on boot; no user-level try/catch can intercept a parse error.

Repro

Bundle linkifyjs for a NativeScript app (or evaluate the module in a V8 build with --no-icu / no ICU data):

import 'linkifyjs'; // SyntaxError: Invalid regular expression: /\p{L}/u

Fix

Declare LETTER/EMOJI as let with ASCII-range fallbacks, then upgrade them via new RegExp('\\p{L}', 'u') / new RegExp('\\p{Emoji}', 'u') inside try/catch. Where ICU exists the behavior is identical; where it doesn't, matching degrades to ASCII letters and the common emoji ranges instead of crashing the bundle.

LETTER and EMOJI were declared as /\p{L}/u and /\p{Emoji}/u literals at
module scope. Embedded JS runtimes built without ICU (e.g. NativeScript's
V8) throw a SyntaxError at parse time for \p{} property escapes — before
any try/catch in user code can run — so importing the package poisons the
whole bundle.

Build the regexes via new RegExp inside try/catch with ASCII-range
fallbacks: identical behavior where ICU exists, graceful degradation
where it doesn't.
aleclarson added a commit to octane-xplat/octane-xplat that referenced this pull request Oct 8, 2026
Filed upstream PRs for the five patch-audit fixes and recorded them via a
new upstreamPR field on the manifest entries:

- nativescript-community/octane#14 — setProp undefined-skip, visibility
  capability, intrinsic ref types
- nativescript-community/octane#15 — vite-octane .tsrx HMR matching and
  recipients counting
- nativescript-community/ui-image#69 — iOS prefetch cacheType + headers
- nfrasser/linkifyjs#572 — ICU-free \p{} regex construction
- facebook/lexical#9334 — @lexical/link URL_REGEX via new RegExp
- NativeScript/NativeScript#11514 — font-weight → wght axis mapping on
  Android (issue #11513)

This branch has not been deployed

No deployments
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