@adguard/hostlist-compiler 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.34] - 2025-01-10
9
+
10
+ ### Removed
11
+
12
+ - Calculation of checksum for filters. [#76]
13
+
14
+ [1.0.34]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.33...v1.0.34
15
+
8
16
  ## [1.0.33] - 2024-12-27
9
17
 
10
18
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adguard/hostlist-compiler",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "A simple tool that compiles hosts blocklists from multiple sources",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.js CHANGED
@@ -4,7 +4,6 @@ const config = require('./configuration');
4
4
  const compileSource = require('./compile-source');
5
5
  const { transform } = require('./transformations/transform');
6
6
  const packageJson = require('../package.json');
7
- const { calculateChecksum } = require('./utils');
8
7
 
9
8
  /**
10
9
  * Prepares list header
@@ -15,6 +14,7 @@ const { calculateChecksum } = require('./utils');
15
14
  */
16
15
  function prepareHeader(configuration) {
17
16
  const lines = [
17
+ '!',
18
18
  `! Title: ${configuration.name}`,
19
19
  ];
20
20
 
@@ -101,12 +101,8 @@ async function compile(configuration) {
101
101
 
102
102
  // Now prepend the list header and we're good to go
103
103
  const header = prepareHeader(configuration);
104
- // Calculate checksum
105
- const checksum = calculateChecksum(header, finalList);
106
- // Concat everything together
107
- const data = [checksum, ...header, ...finalList];
108
- consola.info(`Final length of the list is ${data.length}`);
109
- return data;
104
+ consola.info(`Final length of the list is ${header.length + finalList.length}`);
105
+ return header.concat(finalList);
110
106
  }
111
107
 
112
108
  module.exports = compile;
package/src/utils.js CHANGED
@@ -1,39 +1,7 @@
1
1
  const _ = require('lodash');
2
2
  const fs = require('fs').promises;
3
- const crypto = require('crypto');
4
3
  const axios = require('axios');
5
4
 
6
- /**
7
- * Strips specified character from the end of a string.
8
- *
9
- * @param {string} string - The string to strip.
10
- * @param {string} char - The character to strip.
11
- * @returns {string} - The stripped string.
12
- */
13
- const stripEnd = (str, char) => {
14
- let result = str;
15
- while (result.endsWith(char)) {
16
- result = result.slice(0, -1);
17
- }
18
- return result;
19
- };
20
-
21
- /**
22
- * Calculates checksum for the given header and rules.
23
- * See:
24
- * https://adblockplus.org/en/filters#special-comments
25
- * https://hg.adblockplus.org/adblockplus/file/tip/addChecksum.py
26
- *
27
- * @param {Array<string>} header - The header lines.
28
- * @param {Array<string>} rules - The rules lines.
29
- * @returns {string} - The calculated checksum.
30
- */
31
- const calculateChecksum = (header, rules) => {
32
- const content = header.concat(rules).join('\n');
33
- const checksum = crypto.createHash('md5').update(content).digest('base64');
34
- return `! Checksum: ${stripEnd(checksum.trim(), '=')}`;
35
- };
36
-
37
5
  function isURL(str) {
38
6
  try {
39
7
  // eslint-disable-next-line no-unused-vars
@@ -201,7 +169,6 @@ class Wildcard {
201
169
  }
202
170
 
203
171
  module.exports = {
204
- calculateChecksum,
205
172
  download,
206
173
  Wildcard,
207
174
  splitByDelimiterWithEscapeCharacter,
@@ -1,7 +1,6 @@
1
1
  const nock = require('nock');
2
2
  const consola = require('consola');
3
3
  const compile = require('../src/index');
4
- const { calculateChecksum } = require('../src/utils');
5
4
 
6
5
  describe('Hostlist compiler', () => {
7
6
  it('compile from multiple sources', async () => {
@@ -33,7 +32,6 @@ describe('Hostlist compiler', () => {
33
32
  const list = await compile(configuration);
34
33
 
35
34
  // assert
36
- expect(list[0].startsWith('! Checksum:')).toBe(true);
37
35
  expect(list).toContain('||example.org');
38
36
  expect(list).toContain('||example.com');
39
37
  expect(list).toContain('! Version: 1.0.0.9');
@@ -43,39 +41,4 @@ describe('Hostlist compiler', () => {
43
41
 
44
42
  scope.done();
45
43
  });
46
-
47
- it('calculates checksum correctly', async () => {
48
- // Prepare source
49
- const scope = nock('https://example.org')
50
- .get('/source1.txt')
51
- .reply(200, '||example.org');
52
-
53
- // compiler configuration
54
- const configuration = {
55
- name: 'Test filter',
56
- description: 'Checksum test filter',
57
- version: '1.0.0.1',
58
- sources: [
59
- {
60
- name: 'source 1',
61
- source: 'https://example.org/source1.txt',
62
- },
63
- ],
64
- };
65
-
66
- // compile the final list
67
- const list = await compile(configuration);
68
-
69
- // assert
70
- const checksumLine = list[0];
71
- expect(checksumLine.startsWith('! Checksum:')).toBe(true);
72
-
73
- const header = list.slice(1, list.indexOf('||example.org'));
74
- const finalList = list.slice(list.indexOf('||example.org'));
75
-
76
- const expectedChecksum = calculateChecksum(header, finalList);
77
- expect(checksumLine).toBe(expectedChecksum);
78
-
79
- scope.done();
80
- });
81
44
  });
@@ -34,57 +34,3 @@ describe('substringBetween', () => {
34
34
  expect(substr).toBe(null);
35
35
  });
36
36
  });
37
-
38
- describe('calculateChecksum', () => {
39
- it('calculates checksum with multiple headers and rules', () => {
40
- const header = ['! Title: AdGuard DNS filter', '! Title: Example filter list'];
41
- const rules = ['||example.com^', '||test.com^'];
42
- const expectedChecksum = '! Checksum: VSbHtv4WyU405Fks327CsA';
43
-
44
- const checksum = utils.calculateChecksum(header, rules);
45
- expect(checksum).toBe(expectedChecksum);
46
- });
47
-
48
- it('calculates checksum with empty rules', () => {
49
- const header = ['[Adblock Plus 2.0]'];
50
- const rules = [];
51
- const expectedChecksum = '! Checksum: 87GLA4VsMnV9PiusIkPkEg';
52
-
53
- const checksum = utils.calculateChecksum(header, rules);
54
- expect(checksum).toBe(expectedChecksum);
55
- });
56
-
57
- it('calculates checksum with empty header and rules', () => {
58
- const header = [];
59
- const rules = [];
60
- const expectedChecksum = '! Checksum: 1B2M2Y8AsgTpgAmY7PhCfg';
61
-
62
- const checksum = utils.calculateChecksum(header, rules);
63
- expect(checksum).toBe(expectedChecksum);
64
- });
65
-
66
- it('calculates checksum without stripping empty lines', () => {
67
- const header = [
68
- '! Title: 1Hosts (mini)',
69
- // eslint-disable-next-line max-len
70
- '! Description: List for blocking pesky ads, trackers, and malware. Lenient version: unblocks a number of ads & trackers for in-app rewards, anti-AdBlock, etc.',
71
- '! Version: 1.0.14.48',
72
- '! Homepage: https://badmojr.github.io/1Hosts/',
73
- '! Last modified: 2024-12-27T09:45:56.615Z',
74
- '!',
75
- '! Compiled by @adguard/hostlist-compiler v1.0.32',
76
- '!',
77
- ];
78
- const rules = [
79
- '',
80
- '||logs.netflix.com^',
81
- '||teams.events.data.microsoft.com^',
82
- '||measure.office.net^',
83
- '||app-analytics-services.com^',
84
- ];
85
- const expectedChecksum = '! Checksum: 4v+tPGfpA0fy+xfhlr8P6Q';
86
-
87
- const checksum = utils.calculateChecksum(header, rules);
88
- expect(checksum).toBe(expectedChecksum);
89
- });
90
- });