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

Make mdast-util-gfm-autolink-literal Compatible with Older Browsers (Chrome 49): Remove Lookbehind Assertion #17

Closed
4 tasks done
consistent-k opened this issue Mar 11, 2025 · 5 comments
Labels
👯 no/duplicate Déjà vu 👎 phase/no Post cannot or will not be acted on

Comments

@consistent-k
Copy link

Initial checklist

Affected package

mdast-util-gfm-autolink-literal@latest

Steps to reproduce

  1. Use mdast-util-gfm-autolink-literal in an environment running Chrome 49.
  2. Process a markdown file or text that includes email addresses triggering the regex:
[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu, findEmail]

Observe that Chrome 49 throws a SyntaxError: Invalid regular expression due to the unsupported lookbehind assertion.

Actual behavior

Chrome 49 throws a syntax error because it does not support the (?<=...) lookbehind assertion used in the regex. This stops the library from correctly parsing autolinked email addresses.

Expected behavior

The regex should be modified to avoid the use of lookbehind assertions (e.g., by using non-capturing groups or an alternative matching strategy) so that it can run in legacy browsers like Chrome 49 without throwing an error. This would improve compatibility and allow users with older browser versions to use the library without issues.

Additional context:
Consider replacing the current regex

/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu

with a version that does not rely on lookbehind assertions, such as:

/(?:^|[\s\p{P}\p{S}])(([-.\w+]+)@([-\w]+(?:\.[-\w]+)+))/gu

Note that the consuming code might need to adjust index access to the matched email address.

Thank you for your consideration and for maintaining this project!

Runtime

Chrome 49.0.2623.100

Package manager

[email protected]

Operating system

window xp

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 11, 2025
@JounQin
Copy link
Member

JounQin commented Mar 11, 2025

Please search before creating new issues

@JounQin JounQin closed this as completed Mar 11, 2025

This comment has been minimized.

@JounQin JounQin added the 👯 no/duplicate Déjà vu label Mar 11, 2025
Copy link

Hi! Thanks for taking the time to contribute!

Because we treat issues as our backlog, we close duplicates to focus our work and not have to touch the same chunk of code for the same reason multiple times. This is also why we may mark something as duplicate that isn’t an exact duplicate but is closely related.

Thanks,
— bb

Copy link

github-actions bot commented Mar 11, 2025

Hi team! It seems this post is a duplicate, but hasn’t been marked as such. Please post a comment w/ Duplicate of #123(no final .) to do so. See GH docs for more info.

Thanks,
— bb

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Mar 11, 2025
@JounQin
Copy link
Member

JounQin commented Mar 11, 2025

Duplicate of #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👯 no/duplicate Déjà vu 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants