parse-filter.ts 19 KB

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