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

Allow multiple capture groups for debounce regex action #14687

Merged

Conversation

ShivanKaul
Copy link
Collaborator

@ShivanKaul ShivanKaul commented Aug 17, 2022

Resolves brave/brave-browser#24750

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

The following URLs should get debounced to the publisher URL, once the component update goes out:

https://dev-pages.brave.software/navigation-tracking/debouncing.html, all tests should pass for regression; the one under test is Regex (multi)

@ShivanKaul ShivanKaul self-assigned this Aug 17, 2022
Copy link
Member

@fmarier fmarier left a comment

Choose a reason for hiding this comment

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

Instead of manually adding slashes (and potentially adding them at the end where it may not work), why not simply capture one of the slashes in a capture group?

e.g. instead of ^/([^/]+)/s/(.*)$, we could use ^/([^/]+)/s(/.*)$

components/debounce/browser/debounce_rule.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@pilgrim-brave pilgrim-brave left a comment

Choose a reason for hiding this comment

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

Not opposed to the concept. Deferring to François about the regexes. Definitely needs a lot more tests.

@ShivanKaul ShivanKaul force-pushed the feature/debounce/regex-allow-multiple-capture-groups branch from 0294030 to 88d160e Compare August 18, 2022 02:26
Copy link
Member

@fmarier fmarier left a comment

Choose a reason for hiding this comment

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

That looks good to me, but someone more familiar with Chromium idioms should check whether that's the best way to concatenate StringPieces.

components/debounce/browser/debounce_rule.cc Show resolved Hide resolved
@ShivanKaul
Copy link
Collaborator Author

ShivanKaul commented Aug 18, 2022

That looks good to me, but someone more familiar with Chromium idioms should check whether that's the best way to concatenate StringPieces.

@bridiver any thoughts? https://github.com/brave/brave-core/pull/14687/files#diff-19bb36033aacc98f6f730c5cbda666206d951a19f782c58fca555b7e44765ab3R215

I see several examples in Chromium: [1], [2], [3].

@ShivanKaul ShivanKaul force-pushed the feature/debounce/regex-allow-multiple-capture-groups branch from 88d160e to 29132b6 Compare August 18, 2022 18:00
@ShivanKaul ShivanKaul force-pushed the feature/debounce/regex-allow-multiple-capture-groups branch from 60fdef8 to 319b562 Compare August 18, 2022 19:12
@@ -212,12 +231,14 @@ bool DebounceRule::Apply(const GURL& original_url,
action_ != kDebounceRegexPath)
return false;
// If URL matches an explicitly excluded pattern, this rule does not apply.
if (exclude_pattern_set_.MatchesURL(original_url))
if (exclude_pattern_set_.MatchesURL(original_url)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this diff is not needed, existing formatting is acceptable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know but I just wanted to match everything up. It helps me a tiny bit when I want to add local logging to have these, and given that they're both equivalent I thought might as well. Personally I think always specifying {} is easier to read, but no strong feelings

@ShivanKaul ShivanKaul merged commit ee6eee1 into master Aug 19, 2022
@ShivanKaul ShivanKaul deleted the feature/debounce/regex-allow-multiple-capture-groups branch August 19, 2022 02:54
@github-actions github-actions bot added this to the 1.44.x - Nightly milestone Aug 19, 2022
@MadhaviSeelam
Copy link

@ShivanKaul can you attach testplan please?

@ShivanKaul
Copy link
Collaborator Author

@MadhaviSeelam working on adding a test rule to the debounce.json list, but in the meantime the De-Yandex rules should be sufficient. I've updated the URLs to test in the test plan.

@ShivanKaul
Copy link
Collaborator Author

@MadhaviSeelam updated the test plan with the test rule: https://dev-pages.brave.software/navigation-tracking/debouncing.html, all tests should pass (thanks @pes10k!)

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.

Allow capturing of multiple capture groups for debounce action regex-path
5 participants