Repository navigation
fix(shared): drop a regex lookbehind so the package loads on Safari before 16.4 - #155
Conversation
LONE_SURROGATE_REGEX used a negative lookbehind, which Safari/WebKit only parses from 16.4. unbuild ships regex literals verbatim, so on iOS 15, iOS 16.0-16.3 and older WKWebViews the bundled module failed to load with a SyntaxError before any code ran, breaking browser apps that use the fetch or peer adapters. Use the u-flag class /[\uD800-\uDFFF]/gu instead: in unicode mode a well-formed surrogate pair is a single code point, so only lone surrogates match. Add a repo-level test that fails if any published source file contains a lookbehind, since oxlint has no rule for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dws6kfo5SZKrsmMVu1ADve
Fold the two tests into one so the file list proven non-empty is the one that gets scanned, drop the assertion that only tested the helper's own filter, match per file instead of per line, and resolve the repo root with import.meta.dirname. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dws6kfo5SZKrsmMVu1ADve
@standard-server/aws-lambda
@standard-server/core
@standard-server/fastify
@standard-server/fetch
@standard-server/node
@standard-server/peer
@standard-server/shared
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Regex rewrite —
LONE_SURROGATE_REGEXinpackages/shared/src/uri.ts:2drops the lookbehind/lookahead form for/[\uD800-\uDFFF]/gu; theuflag makes a well-formed surrogate pair a single code point, so only lone surrogates match. - Test cases —
packages/shared/src/uri.test.tsgains three cases mixing well-formed pairs with lone surrogates. - Guardrail test —
tests/browser-compat.test.tsscanspackages/*/srcfor(?<=/(?<!so lookbehind can't re-enter published source.
Verified the new pattern is behaviorally identical to the old one with a 200k-case fuzz over surrogate/astral code units; the new and existing uri tests pass and the guard test discriminates correctly.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dws6kfo5SZKrsmMVu1ADve

LONE_SURROGATE_REGEXinpackages/shared/src/uri.tsused a negative lookbehind ((?<!…)), which Safari/WebKit only parses from 16.4.unbuildcopies regex literals intodist/index.mjsunchanged. So on iOS 15, iOS 16.0–16.3 and older WKWebViews the module, and any bundle chunk that contains it, fails to load withSyntaxError: Invalid regular expression: invalid group specifier namebefore any code runs.@standard-server/coreimportssafeEncodeURIComponentforgenerateContentDisposition, so browser apps using the fetch or peer adapters break on those devices.Fix
/[\uD800-\uDFFF]/gu. With theuflag a well-formed surrogate pair is a single code point, so the class only matches lone surrogates, which still become U+FFFD. Safari has supported theuflag since 10. The try/catch and theoxlint-disablecomments are unchanged.String.prototype.toWellFormed()is not an alternative, since it also needs Safari 16.4.Testing
safeEncodeURIComponentcases still pass. New cases cover'\u{1F600}\uDE00','\u{10FFFF}\uD800', and lone surrogates on both sides of a valid pair.dist/index.mjscontains/[\uD800-\uDFFF]/guand no lookbehind.pnpm run checkandpnpm testpass.🤖 Generated with Claude Code
https://claude.ai/code/session_01Dws6kfo5SZKrsmMVu1ADve