Skip to content

fix(urlpattern): match capture groups in test()/exec()#402

Merged
NathanWalker merged 1 commit into
mainfrom
fix/url-pattern-match
Jul 3, 2026
Merged

fix(urlpattern): match capture groups in test()/exec()#402
NathanWalker merged 1 commit into
mainfrom
fix/url-pattern-match

Conversation

@edusperoni

@edusperoni edusperoni commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

v8_regex_provider::regex_search had two bugs that made URLPattern matching fail (or crash) for any pattern with capture groups:

  • The ToLocal(&item) success check was inverted, so the first successfully read match element bailed out as "no match" and test()/exec() always returned false/null.
  • It included match element 0 (the whole-match string). ada's create_component_match_result pairs exec_result[i] with group_name_list[i] and expects only the capture groups, so the extra element overran group_name_list and crashed once the inverted check was fixed.

Iterate from index 1 and bail only when reading an element fails.

Add URLPattern regression tests covering test() match/non-match and exec() named capture-group extraction and null-on-no-match.

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL pattern matching reliability, including correct capture-group handling and safer match result processing.
    • Fixed an issue where matching URLs could fail or return incorrect results in some cases.
  • Tests
    • Added coverage for matching and non-matching URL patterns.
    • Verified capture groups are extracted correctly and non-matching inputs return no result.

v8_regex_provider::regex_search had two bugs that made URLPattern matching
fail (or crash) for any pattern with capture groups:

- The ToLocal(&item) success check was inverted, so the first successfully
  read match element bailed out as "no match" and test()/exec() always
  returned false/null.
- It included match element 0 (the whole-match string). ada's
  create_component_match_result pairs exec_result[i] with group_name_list[i]
  and expects only the capture groups, so the extra element overran
  group_name_list and crashed once the inverted check was fixed.

Iterate from index 1 and bail only when reading an element fails.

Add URLPattern regression tests covering test() match/non-match and exec()
named capture-group extraction and null-on-no-match.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ae2b0d34-9437-4bdd-b970-f3a9316c13f1

📥 Commits

Reviewing files that changed from the base of the PR and between 268178c and a7ee0c2.

📒 Files selected for processing (2)
  • NativeScript/runtime/URLPatternImpl.cpp
  • TestRunner/app/tests/URLPattern.js

📝 Walkthrough

Walkthrough

Fixes a bug in v8_regex_provider::regex_search where capture-group indexing incorrectly included the whole-match element and an inverted ToLocal check caused false negatives. Adds unit tests validating URLPattern.test() and exec() behavior with named capture groups.

Changes

URLPattern Regex Fix

Layer / File(s) Summary
Fix capture-group indexing and error handling
NativeScript/runtime/URLPatternImpl.cpp
Loop now starts at index 1 to skip the whole-match string, and ToLocal() failure handling is corrected so it only returns std::nullopt on actual conversion failure.
Add URLPattern test/exec coverage
TestRunner/app/tests/URLPattern.js
New tests verify test() returns true/false correctly and exec() extracts named capture groups or returns null on no match.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A bunny hopped through regex trees,
Found index zero causing unease,
Skipped the whole match, kept the groups tight,
Fixed ToLocal's backwards plight,
Now URLPattern hops with ease! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main fix: URLPattern capture groups handling in test() and exec().
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@NathanWalker NathanWalker merged commit 9f21329 into main Jul 3, 2026
9 checks passed
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