Skip to content

Fix double stripping of URLPatternInit search delimiters - #1376

Merged
anonrig merged 2 commits into
ada-url:mainfrom
perfloop-oss:perfloop-pr-open-t7vfgnxrv5
Dec 1, 2026
Merged

anonrig merged 2 commits into
ada-url:mainfrom
perfloop-oss:perfloop-pr-open-t7vfgnxrv5

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

For URLPatternInit input, url_pattern_init::process already removes the single leading ?, and match() and test() then remove a second one. This follows #1171, which made canonicalize_search keep a leading ? and made base-URL inheritance drop the delimiter itself, so the extra removal in match() and test() now removes query data. For search = "??", wildcard matching reports an empty search.input instead of "?"; a literal \? search pattern fails to match, while an empty search pattern incorrectly matches. The same problem affects searches inherited from a base URL such as https://example.com/path??.

Use the processed search directly in match() and test(), as the spec's match steps do ("Set search to applyResult["search"]."); exec() delegates to match(). match() now moves search unconditionally, like the other components. The URL-string path keeps its delimiter handling, and pattern construction is unchanged.

The regression in tests/wpt_urlpattern_tests.cpp uses a literal \? search pattern and structured input with search = "??". It checks that exec() returns a match with search.input == "?" and that test() returns true.

wpt_urlpattern_tests passes: 37 tests, 0 failures, 0 skips (tests/wpt_urlpattern_tests.cpp). Validation uses the repository's std::regex test provider and existing WPT exclusions.

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

Comment thread include/ada/url_pattern-inl.h Outdated
search = apply_result->search->substr(1);
// Canonicalization may have removed tabs or newlines. Do not retain
// that oversized buffer in the result.
search = apply_result->search.value();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is wrong. We check if it starts with ? and remove it. if not we just move the data. Even if we shouldn't remove the question mark from the input, we should still remove this if and only keep std::move line rather than this solution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The pending repair will move search unconditionally in match(), use ASSERT_TRUE in the test, and cover inheritance from base_url = "https://example.com/path??".

@anonrig anonrig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The bug is real and the test() change looks good (url_pattern_init::process already strips the single leading ? in both process_search and base_url inheritance, so match()/test() should not strip a second one).

Requesting one change in match() (include/ada/url_pattern-inl.h): please remove the if (apply_result->search->starts_with("?")) copy branch and unconditionally move:

// Set search to applyResult["search"].
ADA_ASSERT_TRUE(apply_result->search.has_value());
search = std::move(apply_result->search.value());

starts_with("?") is unrelated to whether canonicalize_search removed tabs or newlines:

  • Inputs without a leading ? that had tabs/newlines stripped still take the else branch and move the buffer.
  • Inputs starting with ? that had no tabs/newlines (and searches inherited from base_url, which skip canonicalize_search) pay an unnecessary branch and heap allocation/copy.
  • Every other component in match() (hash, port, pathname, etc.) unconditionally std::moves even though their canonicalizers also call remove_ascii_tab_or_newline.

Minor notes on tests/wpt_urlpattern_tests.cpp:

  • Prefer ASSERT_TRUE(result->has_value()); over EXPECT_TRUE + if (result->has_value()), matching the surrounding tests.
  • Consider also checking the base_url = "https://example.com/path??" inheritance case in the same test since the PR description calls it out.

@perfloop-agent

Copy link
Copy Markdown
Contributor Author

The pending repair will move search unconditionally in match(), use ASSERT_TRUE in the test, and cover inheritance from base_url = "https://example.com/path??".

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.34%. Comparing base (dac95bc) to head (f36f749).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
include/ada/url_pattern-inl.h 0.00% 0 Missing and 2 partials ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1376      +/-   ##
==========================================
+ Coverage   65.31%   65.34%   +0.03%     
==========================================
  Files          43       43              
  Lines        8931     8926       -5     
  Branches     3990     3986       -4     
==========================================
  Hits         5833     5833              
+ Misses        800      799       -1     
+ Partials     2298     2294       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anonrig
anonrig merged commit 361e649 into ada-url:main Dec 1, 2026
52 of 53 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