@adguard/hostlist-compiler 1.0.31 → 1.0.33

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,22 @@ 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.33] - 2024-12-27
9
+
10
+ ### Fixed
11
+
12
+ - Bug with checksum calculation. Leave blank lines when counting. [#76]
13
+
14
+ [1.0.33]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.32...v1.0.33
15
+
16
+ ## [1.0.32] - 2024-12-27
17
+
18
+ ### Fixed
19
+
20
+ - Bug with checksum calculation. Additional line start. [#76]
21
+
22
+ [1.0.32]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.31...v1.0.32
23
+
8
24
  ## [1.0.31] - 2024-12-23
9
25
 
10
26
  ### Fixed
@@ -17,7 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17
33
 
18
34
  [1.0.31]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.29...v1.0.31
19
35
  [#63]: https://github.com/AdguardTeam/HostlistCompiler/issues/63
20
- [#76]: https://github.com/AdguardTeam/FiltersCompiler/issues/76
36
+ [#76]: https://github.com/AdguardTeam/HostlistCompiler/issues/76
21
37
 
22
38
  ## [1.0.29] - 2024-09-26
23
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adguard/hostlist-compiler",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
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
@@ -104,7 +104,7 @@ async function compile(configuration) {
104
104
  // Calculate checksum
105
105
  const checksum = calculateChecksum(header, finalList);
106
106
  // Concat everything together
107
- const data = ['!', checksum, ...header, ...finalList];
107
+ const data = [checksum, ...header, ...finalList];
108
108
  consola.info(`Final length of the list is ${data.length}`);
109
109
  return data;
110
110
  }
package/src/utils.js CHANGED
@@ -18,16 +18,6 @@ const stripEnd = (str, char) => {
18
18
  return result;
19
19
  };
20
20
 
21
- /**
22
- * Normalizes data by replacing newlines.
23
- *
24
- * @param {string} message - The message to normalize.
25
- * @returns {string} - The normalized message.
26
- */
27
- const normalizeData = (message) => {
28
- return message.replace(/\r/g, '').replace(/\n+/g, '\n');
29
- };
30
-
31
21
  /**
32
22
  * Calculates checksum for the given header and rules.
33
23
  * See:
@@ -39,7 +29,7 @@ const normalizeData = (message) => {
39
29
  * @returns {string} - The calculated checksum.
40
30
  */
41
31
  const calculateChecksum = (header, rules) => {
42
- const content = normalizeData(header.concat(rules).join('\n'));
32
+ const content = header.concat(rules).join('\n');
43
33
  const checksum = crypto.createHash('md5').update(content).digest('base64');
44
34
  return `! Checksum: ${stripEnd(checksum.trim(), '=')}`;
45
35
  };
@@ -33,7 +33,7 @@ describe('Hostlist compiler', () => {
33
33
  const list = await compile(configuration);
34
34
 
35
35
  // assert
36
- expect(list[1].startsWith('! Checksum:')).toBe(true);
36
+ expect(list[0].startsWith('! Checksum:')).toBe(true);
37
37
  expect(list).toContain('||example.org');
38
38
  expect(list).toContain('||example.com');
39
39
  expect(list).toContain('! Version: 1.0.0.9');
@@ -67,10 +67,10 @@ describe('Hostlist compiler', () => {
67
67
  const list = await compile(configuration);
68
68
 
69
69
  // assert
70
- const checksumLine = list[1];
70
+ const checksumLine = list[0];
71
71
  expect(checksumLine.startsWith('! Checksum:')).toBe(true);
72
72
 
73
- const header = list.slice(2, list.indexOf('||example.org'));
73
+ const header = list.slice(1, list.indexOf('||example.org'));
74
74
  const finalList = list.slice(list.indexOf('||example.org'));
75
75
 
76
76
  const expectedChecksum = calculateChecksum(header, finalList);
@@ -37,9 +37,9 @@ describe('substringBetween', () => {
37
37
 
38
38
  describe('calculateChecksum', () => {
39
39
  it('calculates checksum with multiple headers and rules', () => {
40
- const header = ['[Adblock Plus 2.0]', '! Title: Example filter list'];
41
- const rules = ['! Checksum: ', '||example.com^', '||test.com^'];
42
- const expectedChecksum = '! Checksum: h0eMYV8/e57vDmGsYZRhsg';
40
+ const header = ['! Title: AdGuard DNS filter', '! Title: Example filter list'];
41
+ const rules = ['||example.com^', '||test.com^'];
42
+ const expectedChecksum = '! Checksum: VSbHtv4WyU405Fks327CsA';
43
43
 
44
44
  const checksum = utils.calculateChecksum(header, rules);
45
45
  expect(checksum).toBe(expectedChecksum);
@@ -62,4 +62,29 @@ describe('calculateChecksum', () => {
62
62
  const checksum = utils.calculateChecksum(header, rules);
63
63
  expect(checksum).toBe(expectedChecksum);
64
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
+ });
65
90
  });