ghostery/adblocker

Failures on options parsing if a filter has `$` character later than actual options index

seia-soto opened this issue · 0 comments

Internals

||www.youtube.com/playlist?list=$xhr,1p,replace=/("trackingParam":"kx_fmPxhoPZR)[-_0-9A-Za-z]{150}[-_0-9A-Za-z]+?([-_0-9A-Za-z]{55}lLKPQ-SS"\})/\$1\$2/

The above filter has a dollar sign later than actual options index. This causes the internal logic to confuse where is actual options index is:

// filters/network.ts
// filter$options == Options
// ^     ^
// |     |
// |     optionsIndex
// filterIndexStart
const optionsIndex: number = line.lastIndexOf('$');

The following REPL shows how the logic failed:

C:\Users\aa\local\repos\adblocker\packages\adblocker>node
Welcome to Node.js v20.11.0.
Type ".help" for more information.
> const filter = String.raw`||www.youtube.com/playlist?list=$xhr,1p,replace=/("trackingParam":"kx_fmPxhoPZR)[-_0-9A-Za-z]{150}[-_0-9A-Za-z]+?([-_0-9A-Za-z]{55}lLKPQ-SS"\})/\$1\$2/`;
undefined
> filter.lastIndexOf('$')
148
> filter.slice(filter.lastIndexOf('$') + 1)
'2/