Skip to content

Commit f3d9819

Browse files
committed
changed the finding attribute value
1 parent dbf2f2f commit f3d9819

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

src/main/builder.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ module.exports = (function () {
255255
return s;
256256
};
257257

258+
/**
259+
* Extracting the value of an attribute.
260+
*
261+
* @param {string} attribute - The input attribute string.
262+
* @returns {string} The extracted attribute value.
263+
*/
264+
const getOptionValue = (attribute) => attribute.slice(attribute.indexOf('="') + 2, -1);
265+
258266
/**
259267
* Parses include line
260268
*
@@ -283,17 +291,8 @@ module.exports = (function () {
283291
exclude = attribute.substring(attribute.indexOf('=') + 1);
284292
exclude = stripEndQuotes(exclude);
285293
} else if (attribute.startsWith(INCLUDE_OPTION_MODIFIERS)) {
286-
// Find the index of the first occurrence of '="' and add 2 to get the start index of the value.
287-
const startIndex = attribute.indexOf('="') + 2;
288-
// Find the index of the last occurrence of '"' to get the end index of the value.
289-
const endIndex = attribute.lastIndexOf('"');
290-
if (startIndex !== -1 && endIndex !== -1) {
291-
// If both start and end indexes are found, extract the value between the quotes.
292-
addModifiers = attribute.slice(startIndex, endIndex);
293-
} else {
294-
// If the quotes are not found, set 'addModifiers' to null.
295-
addModifiers = null;
296-
}
294+
// If value of the option is not specified, then it will be set to null.
295+
addModifiers = getOptionValue(attribute) || null;
297296
}
298297
}
299298

src/main/platforms/generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ module.exports = (() => {
505505
} else {
506506
metadata = removeObsoleteFilters(metadata);
507507
}
508-
508+
// #TODO: https://github.com/AdguardTeam/FiltersCompiler/issues/195
509509
const filtersContent = JSON.stringify(metadata, null, '\t');
510510

511511
fs.writeFileSync(filtersFileJson, filtersContent, 'utf8');

src/test/builder.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ describe('Test builder', () => {
8181
expect(line.trim().endsWith('$image,script')).toBeTruthy();
8282
});
8383
});
84-
85-
it('filter 8 test', async () => {
84+
// Temporarily left at number eight, because under the number of its id (10) in filters.json
85+
// stands above the Base filter and tests for the Base filter, checking the sequence - crashes
86+
// #TODO: fix this
87+
it('filter 10 test', async () => {
8688
// Read the content of the file and split it into lines
8789
const filterContent = await readFile(path.join(filtersDir, 'filter_8_Modifiers', 'filter.txt'));
8890
const filterLines = filterContent.split(/\r?\n/);
@@ -91,7 +93,7 @@ describe('Test builder', () => {
9193
// Get only rule lines without empty lines or comments
9294
const ruleLines = filterLines.filter((line) => !line.startsWith('!') && line.length > 0);
9395
// Check that the number of lines in the file is equal to 10 (excluding comments)
94-
expect(ruleLines.length).toEqual(10);
96+
expect(ruleLines.length).toEqual(15);
9597
// Check that each line (excluding comments) contains '$'
9698
ruleLines
9799
.forEach((line) => {

src/test/resources/filters/cname_trackers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
a155e09a56.reuters.tv
77
albany.townsquarenewsletters.com
88
alerts.dmgt.com
9+
! comment
910
aremedia.e.aremedia.com.au
1011
auto.scissorsscotch.com

src/test/resources/filters/filter_8_Modifiers/template.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
! Homepage: http://adguard.com/filters.html#english
22
! License: http://creativecommons.org/licenses/by-sa/3.0/
33
!
4+
!#if (adguard_app_mac)
5+
@include ../cname_trackers.txt /stripComments /addModifiers="image"
6+
!#endif
47
!#if (adguard_app_ios)
58
@include ../cname_trackers.txt /addModifiers="image,script"
69
!#endif

0 commit comments

Comments
 (0)