parse-filter.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // @ts-check
  2. import { fetchRemoteTextByLine } from './fetch-text-by-line';
  3. import { NetworkFilter } from '@cliqz/adblocker';
  4. import { processLine } from './process-line';
  5. import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
  6. import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
  7. import { traceAsync } from './trace-runner';
  8. import picocolors from 'picocolors';
  9. import { normalizeDomain } from './normalize-domain';
  10. import { fetchAssets } from './fetch-assets';
  11. import { deserializeSet, fsCache, serializeSet } from './cache-filesystem';
  12. const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null
  13. let foundDebugDomain = false;
  14. export function processDomainLists(domainListsUrl: string, includeAllSubDomain = false, ttl: number | null = null) {
  15. return traceAsync(`- processDomainLists: ${domainListsUrl}`, () => fsCache.apply(
  16. domainListsUrl,
  17. async () => {
  18. const domainSets = new Set<string>();
  19. for await (const line of await fetchRemoteTextByLine(domainListsUrl)) {
  20. let domainToAdd = processLine(line);
  21. if (!domainToAdd) continue;
  22. domainToAdd = normalizeDomain(domainToAdd);
  23. if (!domainToAdd) continue;
  24. if (DEBUG_DOMAIN_TO_FIND && domainToAdd.includes(DEBUG_DOMAIN_TO_FIND)) {
  25. console.warn(picocolors.red(domainListsUrl), '(black)', domainToAdd.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND)));
  26. foundDebugDomain = true;
  27. }
  28. domainSets.add(includeAllSubDomain ? `.${domainToAdd}` : domainToAdd);
  29. }
  30. return domainSets;
  31. },
  32. {
  33. ttl,
  34. temporaryBypass: DEBUG_DOMAIN_TO_FIND !== null,
  35. serializer: serializeSet,
  36. deserializer: deserializeSet
  37. }
  38. ));
  39. }
  40. export function processHosts(hostsUrl: string, includeAllSubDomain = false, ttl: number | null = null) {
  41. return traceAsync(`- processHosts: ${hostsUrl}`, () => fsCache.apply(
  42. hostsUrl,
  43. async () => {
  44. const domainSets = new Set<string>();
  45. for await (const l of await fetchRemoteTextByLine(hostsUrl)) {
  46. const line = processLine(l);
  47. if (!line) {
  48. continue;
  49. }
  50. const _domain = line.split(/\s/)[1]?.trim();
  51. if (!_domain) {
  52. continue;
  53. }
  54. const domain = normalizeDomain(_domain);
  55. if (!domain) {
  56. continue;
  57. }
  58. if (DEBUG_DOMAIN_TO_FIND && domain.includes(DEBUG_DOMAIN_TO_FIND)) {
  59. console.warn(picocolors.red(hostsUrl), '(black)', domain.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND)));
  60. foundDebugDomain = true;
  61. }
  62. domainSets.add(includeAllSubDomain ? `.${domain}` : domain);
  63. }
  64. console.log(picocolors.gray('[process hosts]'), picocolors.gray(hostsUrl), picocolors.gray(domainSets.size));
  65. return domainSets;
  66. },
  67. {
  68. ttl,
  69. temporaryBypass: DEBUG_DOMAIN_TO_FIND !== null,
  70. serializer: serializeSet,
  71. deserializer: deserializeSet
  72. }
  73. ));
  74. }
  75. // eslint-disable-next-line sukka-ts/no-const-enum -- bun bundler is smart, maybe?
  76. const enum ParseType {
  77. WhiteIncludeSubdomain = 0,
  78. WhiteAbsolute = -1,
  79. BlackAbsolute = 1,
  80. BlackIncludeSubdomain = 2,
  81. ErrorMessage = 10
  82. }
  83. export async function processFilterRules(
  84. filterRulesUrl: string,
  85. fallbackUrls?: readonly string[] | undefined | null,
  86. ttl: number | null = null
  87. ): Promise<{ white: string[], black: string[], foundDebugDomain: boolean }> {
  88. const [white, black, warningMessages] = await traceAsync(`- processFilterRules: ${filterRulesUrl}`, () => fsCache.apply<Readonly<[
  89. white: string[],
  90. black: string[],
  91. warningMessages: string[]
  92. ]>>(
  93. filterRulesUrl,
  94. async () => {
  95. const whitelistDomainSets = new Set<string>();
  96. const blacklistDomainSets = new Set<string>();
  97. const warningMessages: string[] = [];
  98. const gorhill = await getGorhillPublicSuffixPromise();
  99. /**
  100. * @param {string} line
  101. */
  102. const lineCb = (line: string) => {
  103. const result = parse(line, gorhill);
  104. if (!result) {
  105. return;
  106. }
  107. const flag = result[1];
  108. const hostname = result[0];
  109. if (DEBUG_DOMAIN_TO_FIND) {
  110. if (hostname.includes(DEBUG_DOMAIN_TO_FIND)) {
  111. console.warn(
  112. picocolors.red(filterRulesUrl),
  113. flag === ParseType.WhiteIncludeSubdomain || flag === ParseType.WhiteAbsolute
  114. ? '(white)'
  115. : '(black)',
  116. hostname.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND))
  117. );
  118. foundDebugDomain = true;
  119. }
  120. }
  121. switch (flag) {
  122. case ParseType.WhiteIncludeSubdomain:
  123. if (hostname[0] !== '.') {
  124. whitelistDomainSets.add(`.${hostname}`);
  125. } else {
  126. whitelistDomainSets.add(hostname);
  127. }
  128. break;
  129. case ParseType.WhiteAbsolute:
  130. whitelistDomainSets.add(hostname);
  131. break;
  132. case ParseType.BlackAbsolute:
  133. blacklistDomainSets.add(hostname);
  134. break;
  135. case ParseType.BlackIncludeSubdomain:
  136. if (hostname[0] !== '.') {
  137. blacklistDomainSets.add(`.${hostname}`);
  138. } else {
  139. blacklistDomainSets.add(hostname);
  140. }
  141. break;
  142. case ParseType.ErrorMessage:
  143. warningMessages.push(hostname);
  144. break;
  145. default:
  146. break;
  147. }
  148. };
  149. // TODO-SUKKA: add cache here
  150. if (!fallbackUrls || fallbackUrls.length === 0) {
  151. for await (const line of await fetchRemoteTextByLine(filterRulesUrl)) {
  152. // don't trim here
  153. lineCb(line);
  154. }
  155. } else {
  156. // Avoid event loop starvation, so we wait for a macrotask before we start fetching.
  157. await Promise.resolve();
  158. const filterRules = (await traceAsync(
  159. picocolors.gray(`- download ${filterRulesUrl}`),
  160. () => fetchAssets(filterRulesUrl, fallbackUrls),
  161. picocolors.gray
  162. )).split('\n');
  163. const key = picocolors.gray(`- parse adguard filter ${filterRulesUrl}`);
  164. console.time(key);
  165. for (let i = 0, len = filterRules.length; i < len; i++) {
  166. lineCb(filterRules[i]);
  167. }
  168. console.timeEnd(key);
  169. }
  170. return [
  171. Array.from(whitelistDomainSets),
  172. Array.from(blacklistDomainSets),
  173. warningMessages
  174. ] as const;
  175. },
  176. {
  177. ttl,
  178. temporaryBypass: DEBUG_DOMAIN_TO_FIND !== null,
  179. serializer: JSON.stringify,
  180. deserializer: JSON.parse
  181. }
  182. ));
  183. for (let i = 0, len = warningMessages.length; i < len; i++) {
  184. console.warn(
  185. picocolors.yellow(warningMessages[i]),
  186. picocolors.gray(picocolors.underline(filterRulesUrl))
  187. );
  188. }
  189. console.log(
  190. picocolors.gray('[process filter]'),
  191. picocolors.gray(filterRulesUrl),
  192. picocolors.gray(`white: ${white.length}`),
  193. picocolors.gray(`black: ${black.length}`)
  194. );
  195. return {
  196. white,
  197. black,
  198. foundDebugDomain
  199. };
  200. }
  201. const R_KNOWN_NOT_NETWORK_FILTER_PATTERN = /[#%&=~]/;
  202. const R_KNOWN_NOT_NETWORK_FILTER_PATTERN_2 = /(\$popup|\$removeparam|\$popunder|\$cname)/;
  203. // cname exceptional filter can not be parsed by NetworkFilter
  204. // Surge / Clash can't handle CNAME either, so we just ignore them
  205. function parse($line: string, gorhill: PublicSuffixList): null | [hostname: string, flag: ParseType] {
  206. if (
  207. // doesn't include
  208. !$line.includes('.') // rule with out dot can not be a domain
  209. // includes
  210. || $line.includes('!')
  211. || $line.includes('?')
  212. || $line.includes('*')
  213. || $line.includes('[')
  214. || $line.includes('(')
  215. || $line.includes(']')
  216. || $line.includes(')')
  217. || $line.includes(',')
  218. || R_KNOWN_NOT_NETWORK_FILTER_PATTERN.test($line)
  219. ) {
  220. return null;
  221. }
  222. const line = $line.trim();
  223. /** @example line.length */
  224. const len = line.length;
  225. if (len === 0) {
  226. return null;
  227. }
  228. const firstCharCode = line[0].charCodeAt(0);
  229. const lastCharCode = line[len - 1].charCodeAt(0);
  230. if (
  231. firstCharCode === 47 // 47 `/`
  232. // ends with
  233. || lastCharCode === 46 // 46 `.`, line.endsWith('.')
  234. || lastCharCode === 45 // 45 `-`, line.endsWith('-')
  235. || lastCharCode === 95 // 95 `_`, line.endsWith('_')
  236. // special modifier
  237. || R_KNOWN_NOT_NETWORK_FILTER_PATTERN_2.test(line)
  238. // || line.includes('$popup')
  239. // || line.includes('$removeparam')
  240. // || line.includes('$popunder')
  241. ) {
  242. return null;
  243. }
  244. if ((line.includes('/') || line.includes(':')) && !line.includes('://')) {
  245. return null;
  246. }
  247. const filter = NetworkFilter.parse(line);
  248. if (filter) {
  249. if (
  250. // filter.isCosmeticFilter() // always false
  251. // filter.isNetworkFilter() // always true
  252. filter.isElemHide()
  253. || filter.isGenericHide()
  254. || filter.isSpecificHide()
  255. || filter.isRedirect()
  256. || filter.isRedirectRule()
  257. || filter.hasDomains()
  258. || filter.isCSP() // must not be csp rule
  259. || (!filter.fromAny() && !filter.fromDocument())
  260. ) {
  261. // not supported type
  262. return null;
  263. }
  264. if (
  265. filter.hostname // filter.hasHostname() // must have
  266. && filter.isPlain() // isPlain() === !isRegex()
  267. && (!filter.isFullRegex())
  268. ) {
  269. const hostname = normalizeDomain(filter.hostname);
  270. if (!hostname) {
  271. return null;
  272. }
  273. // |: filter.isHostnameAnchor(),
  274. // |: filter.isLeftAnchor(),
  275. // |https://: !filter.isHostnameAnchor() && (filter.fromHttps() || filter.fromHttp())
  276. const isIncludeAllSubDomain = filter.isHostnameAnchor();
  277. if (filter.isException() || filter.isBadFilter()) {
  278. return [hostname, isIncludeAllSubDomain ? ParseType.WhiteIncludeSubdomain : ParseType.WhiteAbsolute];
  279. }
  280. const _1p = filter.firstParty();
  281. const _3p = filter.thirdParty();
  282. if (_1p) {
  283. if (_1p === _3p) {
  284. return [hostname, isIncludeAllSubDomain ? ParseType.BlackIncludeSubdomain : ParseType.BlackAbsolute];
  285. }
  286. return null;
  287. }
  288. if (_3p) {
  289. return null;
  290. }
  291. }
  292. }
  293. // After NetworkFilter.parse, it means the line can not be parsed by cliqz NetworkFilter
  294. // We now need to "salvage" the line as much as possible
  295. /*
  296. * From now on, we are mostly facing non-standard domain rules (some are regex like)
  297. * We first skip third-party and frame rules, as Surge / Clash can't handle them
  298. *
  299. * `.sharecounter.$third-party`
  300. * `.bbelements.com^$third-party`
  301. * `://o0e.ru^$third-party`
  302. * `.1.1.1.l80.js^$third-party`
  303. */
  304. if (line.includes('$third-party') || line.includes('$frame')) {
  305. return null;
  306. }
  307. /** @example line.endsWith('^') */
  308. const lineEndsWithCaret = lastCharCode === 94; // lastChar === '^';
  309. /** @example line.endsWith('^|') */
  310. const lineEndsWithCaretVerticalBar = (lastCharCode === 124 /** lastChar === '|' */) && line[len - 2] === '^';
  311. /** @example line.endsWith('^') || line.endsWith('^|') */
  312. const lineEndsWithCaretOrCaretVerticalBar = lineEndsWithCaret || lineEndsWithCaretVerticalBar;
  313. // whitelist (exception)
  314. if (
  315. firstCharCode === 64 // 64 `@`
  316. && line[1] === '@'
  317. ) {
  318. let whiteIncludeAllSubDomain = true;
  319. /**
  320. * Some "malformed" regex-based filters can not be parsed by NetworkFilter
  321. * "$genericblock`" is also not supported by NetworkFilter, see:
  322. * https://github.com/ghostery/adblocker/blob/62caf7786ba10ef03beffecd8cd4eec111bcd5ec/packages/adblocker/test/parsing.test.ts#L950
  323. *
  324. * `@@||cmechina.net^$genericblock`
  325. * `@@|ftp.bmp.ovh^|`
  326. * `@@|adsterra.com^|`
  327. * `@@.atlassian.net$document`
  328. * `@@||ad.alimama.com^$genericblock`
  329. */
  330. let sliceStart = 0;
  331. let sliceEnd: number | undefined;
  332. if (line[2] === '|') { // line.startsWith('@@|')
  333. sliceStart = 3;
  334. whiteIncludeAllSubDomain = false;
  335. if (line[3] === '|') { // line.startsWith('@@||')
  336. sliceStart = 4;
  337. whiteIncludeAllSubDomain = true;
  338. }
  339. } else if (line[2] === '.') { // line.startsWith('@@.')
  340. sliceStart = 3;
  341. whiteIncludeAllSubDomain = true;
  342. } else if (
  343. /**
  344. * line.startsWith('@@://')
  345. *
  346. * `@@://googleadservices.com^|`
  347. * `@@://www.googleadservices.com^|`
  348. */
  349. line[2] === ':' && line[3] === '/' && line[4] === '/'
  350. ) {
  351. whiteIncludeAllSubDomain = false;
  352. sliceStart = 5;
  353. }
  354. if (lineEndsWithCaretOrCaretVerticalBar) {
  355. sliceEnd = -2;
  356. } else if (line.endsWith('$genericblock')) {
  357. sliceEnd = -13;
  358. if (line[len - 14] === '^') { // line.endsWith('^$genericblock')
  359. sliceEnd = -14;
  360. }
  361. } else if (line.endsWith('$document')) {
  362. sliceEnd = -9;
  363. if (line[len - 10] === '^') { // line.endsWith('^$document')
  364. sliceEnd = -10;
  365. }
  366. }
  367. if (sliceStart !== 0 || sliceEnd !== undefined) {
  368. const sliced = line.slice(sliceStart, sliceEnd);
  369. const domain = normalizeDomain(sliced);
  370. if (domain) {
  371. return [domain, whiteIncludeAllSubDomain ? ParseType.WhiteIncludeSubdomain : ParseType.WhiteAbsolute];
  372. }
  373. return [
  374. `[parse-filter E0001] (white) invalid domain: ${JSON.stringify({
  375. line, sliced, sliceStart, sliceEnd
  376. })}`,
  377. ParseType.ErrorMessage
  378. ];
  379. }
  380. return [
  381. `[parse-filter E0006] (white) failed to parse: ${JSON.stringify({
  382. line, sliceStart, sliceEnd
  383. })}`,
  384. ParseType.ErrorMessage
  385. ];
  386. }
  387. if (
  388. // 124 `|`
  389. // line.startsWith('|')
  390. firstCharCode === 124
  391. && lineEndsWithCaretOrCaretVerticalBar
  392. ) {
  393. /**
  394. * Some malformed filters can not be parsed by NetworkFilter:
  395. *
  396. * `||smetrics.teambeachbody.com^.com^`
  397. * `||solutions.|pages.indigovision.com^`
  398. * `||vystar..0rg@client.iebetanialaargentina.edu.co^`
  399. * `app-uat.latrobehealth.com.au^predirect.snapdeal.com`
  400. */
  401. const includeAllSubDomain = line[1] === '|';
  402. const sliceStart = includeAllSubDomain ? 2 : 1;
  403. const sliceEnd = lineEndsWithCaret
  404. ? -1
  405. : (lineEndsWithCaretVerticalBar ? -2 : undefined);
  406. const sliced = line.slice(sliceStart, sliceEnd); // we already make sure line startsWith "|"
  407. const domain = normalizeDomain(sliced);
  408. if (domain) {
  409. return [domain, includeAllSubDomain ? ParseType.BlackIncludeSubdomain : ParseType.BlackAbsolute];
  410. }
  411. return [
  412. `[parse-filter E0002] (black) invalid domain: ${sliced}`,
  413. ParseType.ErrorMessage
  414. ];
  415. }
  416. const lineStartsWithSingleDot = firstCharCode === 46; // 46 `.`
  417. if (
  418. lineStartsWithSingleDot
  419. && lineEndsWithCaretOrCaretVerticalBar
  420. ) {
  421. /**
  422. * `.ay.delivery^`
  423. * `.m.bookben.com^`
  424. * `.wap.x4399.com^`
  425. */
  426. const sliced = line.slice(
  427. 1, // remove prefix dot
  428. lineEndsWithCaret // replaceAll('^', '')
  429. ? -1
  430. : (lineEndsWithCaretVerticalBar ? -2 : undefined) // replace('^|', '')
  431. );
  432. const suffix = gorhill.getPublicSuffix(sliced);
  433. if (!gorhill.suffixInPSL(suffix)) {
  434. // This exclude domain-like resource like `1.1.4.514.js`
  435. return null;
  436. }
  437. const domain = normalizeDomain(sliced);
  438. if (domain) {
  439. return [domain, ParseType.BlackIncludeSubdomain];
  440. }
  441. return [
  442. `[paparse-filter E0003] (black) invalid domain: ${sliced}`,
  443. ParseType.ErrorMessage
  444. ];
  445. }
  446. /**
  447. * `|http://x.o2.pl^`
  448. * `://mine.torrent.pw^`
  449. * `://say.ac^`
  450. */
  451. if (lineEndsWithCaretOrCaretVerticalBar) {
  452. let sliceStart = 0;
  453. let sliceEnd;
  454. if (lineEndsWithCaret) { // line.endsWith('^')
  455. sliceEnd = -1;
  456. } else if (lineEndsWithCaretVerticalBar) { // line.endsWith('^|')
  457. sliceEnd = -2;
  458. }
  459. if (line.startsWith('://')) {
  460. sliceStart = 3;
  461. } else if (line.startsWith('http://')) {
  462. sliceStart = 7;
  463. } else if (line.startsWith('https://')) {
  464. sliceStart = 8;
  465. } else if (line.startsWith('|http://')) {
  466. sliceStart = 8;
  467. } else if (line.startsWith('|https://')) {
  468. sliceStart = 9;
  469. }
  470. if (sliceStart !== 0 || sliceEnd !== undefined) {
  471. const sliced = line.slice(sliceStart, sliceEnd);
  472. const domain = normalizeDomain(sliced);
  473. if (domain) {
  474. return [domain, ParseType.BlackIncludeSubdomain];
  475. }
  476. return [
  477. `[parse-filter E0004] (black) invalid domain: ${JSON.stringify({
  478. line, sliced, sliceStart, sliceEnd
  479. })}`,
  480. ParseType.ErrorMessage
  481. ];
  482. }
  483. }
  484. /**
  485. * `_vmind.qqvideo.tc.qq.com^`
  486. * `arketing.indianadunes.com^`
  487. * `charlestownwyllie.oaklawnnonantum.com^`
  488. * `-telemetry.officeapps.live.com^`
  489. * `-tracker.biliapi.net`
  490. * `-logging.nextmedia.com`
  491. * `_social_tracking.js^`
  492. */
  493. if (
  494. firstCharCode !== 124 // 124 `|`
  495. && lastCharCode === 94 // 94 `^`
  496. ) {
  497. const _domain = line.slice(0, -1);
  498. const suffix = gorhill.getPublicSuffix(_domain);
  499. if (!suffix || !gorhill.suffixInPSL(suffix)) {
  500. // This exclude domain-like resource like `_social_tracking.js^`
  501. return null;
  502. }
  503. const domain = normalizeDomain(_domain);
  504. if (domain) {
  505. return [domain, ParseType.BlackAbsolute];
  506. }
  507. return [
  508. `[parse-filter E0005] (black) invalid domain: ${_domain}`,
  509. ParseType.ErrorMessage
  510. ];
  511. }
  512. // Possibly that entire rule is domain
  513. /**
  514. * lineStartsWithSingleDot:
  515. *
  516. * `.cookielaw.js`
  517. * `.content_tracking.js`
  518. * `.ads.css`
  519. *
  520. * else:
  521. *
  522. * `_prebid.js`
  523. * `t.yesware.com`
  524. * `ubmcmm.baidustatic.com`
  525. * `://www.smfg-card.$document`
  526. * `portal.librus.pl$$advertisement-module`
  527. * `@@-ds.metric.gstatic.com^|`
  528. * `://gom.ge/cookie.js`
  529. * `://accout-update-smba.jp.$document`
  530. * `_200x250.png`
  531. * `@@://www.liquidweb.com/kb/wp-content/themes/lw-kb-theme/images/ads/vps-sidebar.jpg`
  532. */
  533. let sliceStart = 0;
  534. let sliceEnd: number | undefined;
  535. if (lineStartsWithSingleDot) {
  536. sliceStart = 1;
  537. }
  538. if (line.endsWith('^$all')) { // This salvage line `thepiratebay3.com^$all`
  539. sliceEnd = -5;
  540. } else if (
  541. // Try to salvage line like `://account.smba.$document`
  542. // For this specific line, it will fail anyway though.
  543. line.endsWith('$document')
  544. ) {
  545. sliceEnd = -9;
  546. }
  547. const sliced = (sliceStart !== 0 || sliceEnd !== undefined) ? line.slice(sliceStart, sliceEnd) : line;
  548. const suffix = gorhill.getPublicSuffix(sliced);
  549. /**
  550. * Fast exclude definitely not domain-like resource
  551. *
  552. * `.gatracking.js`, suffix is `js`,
  553. * `.ads.css`, suffix is `css`,
  554. * `-cpm-ads.$badfilter`, suffix is `$badfilter`,
  555. * `portal.librus.pl$$advertisement-module`, suffix is `pl$$advertisement-module`
  556. */
  557. if (!suffix || !gorhill.suffixInPSL(suffix)) {
  558. // This exclude domain-like resource like `.gatracking.js`, `.beacon.min.js` and `.cookielaw.js`
  559. return null;
  560. }
  561. const tryNormalizeDomain = normalizeDomain(sliced);
  562. if (tryNormalizeDomain === sliced) {
  563. // the entire rule is domain
  564. return [sliced, ParseType.BlackIncludeSubdomain];
  565. }
  566. return [
  567. `[parse-filter E0010] can not parse: ${line}`,
  568. ParseType.ErrorMessage
  569. ];
  570. }