Repository navigation
Fix double stripping of URLPatternInit search delimiters - #1376
Conversation
Signed-off-by: Perfloop Agent <[email protected]>
| 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 theelsebranch and move the buffer. - Inputs starting with
?that had no tabs/newlines (and searches inherited frombase_url, which skipcanonicalize_search) pay an unnecessary branch and heap allocation/copy. - Every other component in
match()(hash,port,pathname, etc.) unconditionallystd::moves even though their canonicalizers also callremove_ascii_tab_or_newline.
Minor notes on tests/wpt_urlpattern_tests.cpp:
- Prefer
ASSERT_TRUE(result->has_value());overEXPECT_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.
|
The pending repair will move search unconditionally in |
Signed-off-by: Perfloop Agent <[email protected]>
Codecov Report❌ Patch coverage is
❌ 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. 🚀 New features to boost your workflow:
|
For
URLPatternInitinput,url_pattern_init::processalready removes the single leading?, andmatch()andtest()then remove a second one. This follows #1171, which madecanonicalize_searchkeep a leading?and made base-URL inheritance drop the delimiter itself, so the extra removal inmatch()andtest()now removes query data. Forsearch = "??", wildcard matching reports an emptysearch.inputinstead 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 ashttps://example.com/path??.Use the processed search directly in
match()andtest(), as the spec's match steps do ("Set search to applyResult["search"].");exec()delegates tomatch().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.cppuses a literal\?search pattern and structured input withsearch = "??". It checks thatexec()returns a match withsearch.input == "?"and thattest()returns true.wpt_urlpattern_testspasses: 37 tests, 0 failures, 0 skips (tests/wpt_urlpattern_tests.cpp). Validation uses the repository'sstd::regextest provider and existing WPT exclusions.Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.