parse-filter.ts 19 KB

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