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

feat: $removeparam #4528

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
94f5868
feat: `$removeparam`
seia-soto Dec 13, 2024
29e9c39
fix: check `parametersRemoved` to prevent infinite loop
seia-soto Dec 13, 2024
3ec1181
fix: parsing and restoration
seia-soto Dec 13, 2024
fd43ad1
feat: removeparam without option value
seia-soto Dec 13, 2024
9497047
refactor: drop use of URLSearchParams
seia-soto Dec 25, 2024
56f90cc
feat: introduce `NetworkFilter.prototype.isRedirectable`
seia-soto Dec 25, 2024
47b1302
refactor: improve matching search param key
seia-soto Dec 25, 2024
7ea4488
test: removeparam
seia-soto Dec 27, 2024
29e9022
test: removeparam removes parameter sequentially
seia-soto Dec 27, 2024
3cb0861
fix(test): unintentional isRedirectable definition
seia-soto Dec 27, 2024
9c1e12b
refactor: use `URL` constructor
seia-soto Jan 6, 2025
c8da3bb
refactor: clarify `removeparam` getter
seia-soto Jan 6, 2025
533110e
refactor: move heavy calls to `before`
seia-soto Jan 14, 2025
1c07025
fix(test): invalid scopes
seia-soto Jan 15, 2025
90d051b
refactor: remove url transforms outside of before hook
seia-soto Jan 15, 2025
ec917aa
fix: removeparam exception
seia-soto Jan 16, 2025
c1db908
fix(test): make global removeparam work with malformed urls
seia-soto Jan 16, 2025
d48fe63
fix(test): correct bucket location
seia-soto Jan 16, 2025
88f35a1
fix: convert to unsigned int on set
seia-soto Jan 23, 2025
160febd
fix: convert to unsigned int on bit clear
seia-soto Jan 23, 2025
4040a89
fix: modify mask safely when applying cpt mask
seia-soto Jan 23, 2025
90ce5c2
fix: make mask unsigned at the end of parse
seia-soto Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: removeparam without option value
  • Loading branch information
seia-soto committed Dec 13, 2024
commit fd43ad1e1012375d0da9355f3b851205fd261b35
15 changes: 12 additions & 3 deletions packages/adblocker/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1479,9 +1479,18 @@ export default class FilterEngine extends EventEmitter<EngineEventHandlers> {
const searchParams = new URLSearchParams(request.url.slice(searchParamsIndex + 1));
let parametersRemoved = 0;
for (const redirect of requestRedirects) {
if (searchParams.has(redirect.optionValue!)) {
parametersRemoved++;
searchParams.delete(redirect.optionValue!);
// When removeparam used without any option value, remove all parameter.
if (redirect.optionValue === undefined) {
redirectUrl = request.url.slice(0, searchParamsIndex);
result.filter = requestRedirects[0];
// Prevent next branch after the loop to be executed.
parametersRemoved = 0;
break;
} else {
if (searchParams.has(redirect.optionValue)) {
parametersRemoved++;
searchParams.delete(redirect.optionValue);
}
}
}
if (parametersRemoved !== 0) {
Expand Down
10 changes: 5 additions & 5 deletions packages/adblocker/src/filters/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,6 @@ export default class NetworkFilter implements IFilter {

break;
case 'removeparam':
if (value.length === 0) {
return null;
}

mask = setBit(mask, NETWORK_FILTER_MASK.isRemoveParam);
optionValue = value;

Expand Down Expand Up @@ -1546,7 +1542,11 @@ export default class NetworkFilter implements IFilter {
}

if (this.isRemoveParam()) {
options.push(`removeparam=${this.optionValue!}`);
if (this.optionValue !== undefined) {
options.push(`removeparam=${this.optionValue}`);
} else {
options.push('removeparam');
seia-soto marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (options.length > 0) {
Expand Down
Loading