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

/^.$/us is transpiled incorrectly #74

Closed
thorn0 opened this issue May 17, 2021 · 4 comments
Closed

/^.$/us is transpiled incorrectly #74

thorn0 opened this issue May 17, 2021 · 4 comments

Comments

@thorn0
Copy link

thorn0 commented May 17, 2021

Current output:

const transpiled = /^(?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])$/

Actual result:

transpiled.test('\u0001\udc00'); // true

Expected result:

/^.$/us.test('\u0001\udc00'); // false
@jridgewell
Copy link
Collaborator

It's last branch (?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF] which is causing the error. (?:[^\uD800-\uDBFF]|^) is eating the \u0001 and [\uDC00-\uDFFF] is matching the \udc00. See #17 for context why this happens, and mathiasbynens/regenerate#28. Unfortunately, it's not possible to implement correctly without lookbehinds.

@thorn0
Copy link
Author

thorn0 commented May 18, 2021

Okay, I just wanted to report a bug. If it's a known thing, feel free to close the issue.

@jridgewell
Copy link
Collaborator

/cc @mathiasbynens

@mathiasbynens
Copy link
Owner

This is the fourth bullet point on https://github.com/mathiasbynens/regexpu#known-limitations:

  1. regexpu doesn’t match lone low surrogates accurately. Unfortunately that is impossible to implement due to the lack of lookbehind support in JavaScript regular expressions.

JSC/Safari still doesn't support lookbehinds, so this phrasing is still accurate even for projects that only need to consider modern JS environments. :(

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

3 participants