colinhacks / zod

TypeScript-first schema validation with static type inference

Home Page:https://zod.dev

Repository from Github https://github.comcolinhacks/zodRepository from Github https://github.comcolinhacks/zod

emoji regular expression issue - Ln 666 - relating "beast Regex" blog entry

LennyDtech opened this issue · comments

Issue relates to Regex handler for emojis code
Compatibility concern with latest browsers, any advice?

// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
let emojiRegex: RegExp;

Angular V18 runtime library throws:

Unicode property escapes in regular expressions are not available in the configured target environment ("chrome133.0", "edge131.0", "firefox128.0", "ios17.0", "safari17.0" + 5 overrides) [unsupported-regexp]

y = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u,

This regular expression literal has been converted to a "new RegExp()" constructor to avoid
generating code with a syntax error. However, you will need to include a polyfill for "RegExp" for
your code to have the correct behavior at run-time.

Hi, @LennyDtech. I'm Dosu, and I'm helping the Zod team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Compatibility issue with Zod's handling of emojis using Unicode property escapes.
  • The issue causes runtime errors in Angular V18 due to lack of support in the latest browser versions.
  • Suggested solution: Implement a polyfill for RegExp.
  • No further comments or developments have been made on this issue.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of the Zod repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 14 days.

Thank you for your understanding and contribution!

The reason that regex is lazily instantiated from a string is to avoid compatibility issues on platforms that don't support it. Basically my guidance is to avoid z.emoji() if you need legacy compatibility. You can use .regex() with one of the older emoji regexez (but they're too hacky for Zod core, imo)