Skip to content

Port lre fixes 1#1425

Open
saghul wants to merge 4 commits intomasterfrom
lre-fixes-1
Open

Port lre fixes 1#1425
saghul wants to merge 4 commits intomasterfrom
lre-fixes-1

Conversation

@saghul
Copy link
Copy Markdown
Contributor

@saghul saghul commented Mar 26, 2026

Disclaimer: I used AI to port the patches, and then reviewed them myself.

  • Fix RegExp.prototype[Symbol.split] to not coerce captures to strings
  • Fix Regexp.prototype[Symbol.match] to use CreateDataPropertyOrThrow
  • Adjust lastIndex to leading surrogate in unicode RegExp
  • Make \x{N} a syntax error in escape sequences

@saghul saghul marked this pull request as draft March 26, 2026 15:37
@saghul saghul marked this pull request as ready for review March 26, 2026 15:40
@saghul saghul requested a review from bnoordhuis March 27, 2026 22:10
Comment on lines +2540 to +2543
const uint16_t *p = (const uint16_t *)cptr;
if (is_lo_surrogate(*p) && is_hi_surrogate(p[-1])) {
cptr = (const uint8_t *)(p - 1);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe/unsound when the pointer is unaligned. Something like this is sound (assuming it's not readying before the start of the buffer, of course):

Suggested change
const uint16_t *p = (const uint16_t *)cptr;
if (is_lo_surrogate(*p) && is_hi_surrogate(p[-1])) {
cptr = (const uint8_t *)(p - 1);
}
uint16_t c[2];
memcpy(c, &cptr[-2], sizeof(c));
if (is_lo_surrogate(c[1]) && is_hi_surrogate(c[0])) {
cptr -= 2;
}

The high/low surrogate checks look inverted though.

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

Successfully merging this pull request may close these issues.

2 participants