Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: AutoLinkPlugin's negative lookbehind breaks in older browsers #6573

Open
castvoid opened this issue Aug 28, 2024 · 0 comments
Open

Bug: AutoLinkPlugin's negative lookbehind breaks in older browsers #6573

castvoid opened this issue Aug 28, 2024 · 0 comments

Comments

@castvoid
Copy link

Lexical version: 0.17.1 (latest)

Steps To Reproduce

  1. Use Safari v15
  2. Visit a site that uses Lexical with AutoLinkPlugin, e.g., https://playground.lexical.dev/
  3. Observe that the site fails to load due to an exception
SyntaxError: Invalid regular expression: invalid group specifier name

image

Removing the negative lookbehind here appears to fix the issue, but causes a regression for #6146:

const URL_REGEX =
/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)(?<![-.+():%])/;

A more graceful fix might be something like:

let URL_REGEX: RegExp;

try {
  URL_REGEX =
    /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)(?<![-.+():%])/;
} catch (e) {
  console.info('Failed to define URL_REGEX - falling back to basic version without negative lookbehind', e);
  URL_REGEX =
    /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
}

Link to code example: https://playground.lexical.dev/

The current behavior

Lexical crashes

The expected behavior

Lexical works :)

Impact of fix

This breaks Lexical on affected browsers. caniuse indicates that Safari <16.4 (March 2023) is affected in particular.

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

No branches or pull requests

1 participant