Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1675527
fix travis.yml
slvvko Jul 8, 2020
28dfc72
fix hooks
slvvko Jul 8, 2020
f6c8a14
clean cache for travis
slvvko Jul 8, 2020
16fcb3c
echo travis vars
slvvko Jul 8, 2020
5ec6afd
up node to 12
slvvko Jul 8, 2020
c065953
back to node10 and build.sh trying
slvvko Jul 9, 2020
c90e153
try node 14
slvvko Jul 9, 2020
444b76f
get node 10 back
slvvko Jul 9, 2020
89a2494
try to fix travis
slvvko Jul 10, 2020
6d30066
try to fix travis
slvvko Jul 10, 2020
a9c154a
try to fix travis
slvvko Jul 10, 2020
e3388b4
try to fix travis
slvvko Jul 10, 2020
4047ea4
try to fix travis
slvvko Jul 10, 2020
b227c57
try to fix travis
slvvko Jul 10, 2020
9df7e0d
try to fix travis
slvvko Jul 10, 2020
fae5df0
try to fix travis
slvvko Jul 10, 2020
852b6e8
try to fix travis
slvvko Jul 10, 2020
38c478d
try to fix travis
slvvko Jul 10, 2020
f09ee31
disable cache
slvvko Jul 10, 2020
d4a0e8c
upgrade yarn
slvvko Jul 10, 2020
cb4604f
merge upstream + rebuild
slvvko Aug 4, 2020
bcd091b
Merge remote-tracking branch 'upstream/master'
slvvko Aug 6, 2020
562638c
Merge remote-tracking branch 'upstream/master'
slvvko Sep 3, 2020
02ded91
try to export Redirects class
slvvko Sep 3, 2020
a75329e
one more update
slvvko Sep 3, 2020
3991f6f
one more update
slvvko Sep 4, 2020
406c03e
merge upstream
slvvko Nov 6, 2020
40a2df6
one more update
slvvko Nov 6, 2020
464691c
one more update
slvvko Nov 6, 2020
80dff76
one more update
slvvko Nov 23, 2020
5d56135
one more update
slvvko Nov 23, 2020
a5e7e53
set -u
slvvko Nov 23, 2020
7d4690e
one more update
slvvko Nov 23, 2020
1c5464c
one more update
slvvko Nov 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ cache: false

script:
- bash -e ./build.sh

notifications:
slack: performix:yXTihlSzsLFSZiqbXMNzvTSX
51 changes: 29 additions & 22 deletions dist/cjs/scriptlets.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4170,34 +4170,41 @@ var isAbpRedirectCompatibleWithAdg = function isAbpRedirectCompatibleWithAdg(rul


var hasValidContentType = function hasValidContentType(rule) {
if (isRedirectRuleByType(rule, 'ADG')) {
var ruleModifiers = parseModifiers(rule); // rule can have more than one source type modifier
if (!isRedirectRuleByType(rule, 'ADG')) {
throw new Error("Unable to convert - not an ADG rule: ".concat(rule));
}

var sourceTypes = ruleModifiers.filter(function (el) {
return VALID_SOURCE_TYPES.indexOf(el) > -1;
});
var isSourceTypeSpecified = sourceTypes.length > 0;
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;

if (isEmptyRedirect) {
if (isSourceTypeSpecified) {
var isValidType = sourceTypes.reduce(function (acc, sType) {
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
return type === sType;
});
return !!isEmptySupported && acc;
}, true);
return isValidType;
} // no source type for 'empty' is allowed
if (!isAdgRedirectCompatibleWithUbo(rule)) {
throw new Error("Unable to convert - unsupported by uBO redirect in rule: ".concat(rule));
} // if (isAdgRedirectCompatibleWithUbo(rule)) {
// if (isRedirectRuleByType(rule, 'ADG')) {


return true;
}
var ruleModifiers = parseModifiers(rule); // rule can have more than one source type modifier

return isSourceTypeSpecified;
var sourceTypes = ruleModifiers.filter(function (el) {
return VALID_SOURCE_TYPES.indexOf(el) > -1;
});
var isSourceTypeSpecified = sourceTypes.length > 0;
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;

if (isEmptyRedirect) {
if (isSourceTypeSpecified) {
var isValidType = sourceTypes.reduce(function (acc, sType) {
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
return type === sType;
});
return !!isEmptySupported && acc;
}, true);
return isValidType;
} // no source type for 'empty' is allowed


return true;
}

return false;
return isSourceTypeSpecified; // }
// return false;
};

var validator = {
Expand Down
51 changes: 29 additions & 22 deletions dist/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4171,34 +4171,41 @@


var hasValidContentType = function hasValidContentType(rule) {
if (isRedirectRuleByType(rule, 'ADG')) {
var ruleModifiers = parseModifiers(rule); // rule can have more than one source type modifier
if (!isRedirectRuleByType(rule, 'ADG')) {
throw new Error("Unable to convert - not an ADG rule: ".concat(rule));
}

var sourceTypes = ruleModifiers.filter(function (el) {
return VALID_SOURCE_TYPES.indexOf(el) > -1;
});
var isSourceTypeSpecified = sourceTypes.length > 0;
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;

if (isEmptyRedirect) {
if (isSourceTypeSpecified) {
var isValidType = sourceTypes.reduce(function (acc, sType) {
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
return type === sType;
});
return !!isEmptySupported && acc;
}, true);
return isValidType;
} // no source type for 'empty' is allowed
if (!isAdgRedirectCompatibleWithUbo(rule)) {
throw new Error("Unable to convert - unsupported by uBO redirect in rule: ".concat(rule));
} // if (isAdgRedirectCompatibleWithUbo(rule)) {
// if (isRedirectRuleByType(rule, 'ADG')) {


return true;
}
var ruleModifiers = parseModifiers(rule); // rule can have more than one source type modifier

return isSourceTypeSpecified;
var sourceTypes = ruleModifiers.filter(function (el) {
return VALID_SOURCE_TYPES.indexOf(el) > -1;
});
var isSourceTypeSpecified = sourceTypes.length > 0;
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;

if (isEmptyRedirect) {
if (isSourceTypeSpecified) {
var isValidType = sourceTypes.reduce(function (acc, sType) {
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
return type === sType;
});
return !!isEmptySupported && acc;
}, true);
return isValidType;
} // no source type for 'empty' is allowed


return true;
}

return false;
return isSourceTypeSpecified; // }
// return false;
};

var validator = {
Expand Down
54 changes: 31 additions & 23 deletions src/helpers/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,31 +347,39 @@ const isAbpRedirectCompatibleWithAdg = (rule) => {
* @returns {boolean}
*/
const hasValidContentType = (rule) => {
if (isRedirectRuleByType(rule, 'ADG')) {
const ruleModifiers = parseModifiers(rule);
// rule can have more than one source type modifier
const sourceTypes = ruleModifiers
.filter((el) => VALID_SOURCE_TYPES.indexOf(el) > -1);

const isSourceTypeSpecified = sourceTypes.length > 0;
const isEmptyRedirect = ruleModifiers.indexOf(`${ADG_UBO_REDIRECT_MARKER}${EMPTY_REDIRECT_MARKER}`) > -1;

if (isEmptyRedirect) {
if (isSourceTypeSpecified) {
const isValidType = sourceTypes.reduce((acc, sType) => {
const isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES
.find((type) => type === sType);
return !!isEmptySupported && acc;
}, true);
return isValidType;
}
// no source type for 'empty' is allowed
return true;
}
if (!isRedirectRuleByType(rule, 'ADG')) {
throw new Error(`Unable to convert - not an ADG rule: ${rule}`);
}
if (!isAdgRedirectCompatibleWithUbo(rule)) {
throw new Error(`Unable to convert - unsupported by uBO redirect in rule: ${rule}`);
}

return isSourceTypeSpecified;
// if (isAdgRedirectCompatibleWithUbo(rule)) {
// if (isRedirectRuleByType(rule, 'ADG')) {
const ruleModifiers = parseModifiers(rule);
// rule can have more than one source type modifier
const sourceTypes = ruleModifiers
.filter((el) => VALID_SOURCE_TYPES.indexOf(el) > -1);

const isSourceTypeSpecified = sourceTypes.length > 0;
const isEmptyRedirect = ruleModifiers.indexOf(`${ADG_UBO_REDIRECT_MARKER}${EMPTY_REDIRECT_MARKER}`) > -1;

if (isEmptyRedirect) {
if (isSourceTypeSpecified) {
const isValidType = sourceTypes.reduce((acc, sType) => {
const isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES
.find((type) => type === sType);
return !!isEmptySupported && acc;
}, true);
return isValidType;
}
// no source type for 'empty' is allowed
return true;
}
return false;

return isSourceTypeSpecified;
// }
// return false;
};

const validator = {
Expand Down
21 changes: 18 additions & 3 deletions tests/lib-tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ test('Test redirect rule validation', (assert) => {
// invalid redirect name
inputRule = '||example.orf^$media,redirect=no-mp4';
assert.strictEqual(validator.isAdgRedirectCompatibleWithUbo(inputRule), false);
// no ubo analog for redirect
inputRule = '||example.com/ad/vmap/*$xmlhttprequest,redirect=noopvmap-1.0';
assert.strictEqual(validator.isAdgRedirectCompatibleWithUbo(inputRule), false);
// rules with 'redirect=' marker in base rule part should be skipped
inputRule = '_redirect=*://look.$popup';
assert.strictEqual(validator.isAdgRedirectCompatibleWithUbo(inputRule), false);
Expand Down Expand Up @@ -247,9 +250,11 @@ test('Test redirect rule validation for ADG -> UBO converting', (assert) => {
adgRule = '||example.com/images/*.png$image,important,redirect=1x1-transparent.gif,domain=example.com|example.org';
assert.strictEqual(validator.hasValidContentType(adgRule), true);

// abp rule ->> false
adgRule = '||example.com^$script,rewrite=abp-resource:blank-js';
assert.strictEqual(validator.hasValidContentType(adgRule), false);
// abp rule ->> error because only ADG rules accepted
assert.throws(() => {
adgRule = '||example.com^$script,rewrite=abp-resource:blank-js';
convertAdgRedirectToUbo(adgRule);
}, 'unable to convert -- no such ubo redirect');

// no source type
adgRule = '||example.com^$important,redirect=nooptext';
Expand Down Expand Up @@ -279,4 +284,14 @@ test('Test REDIRECT converting - ADG -> UBO', (assert) => {
adgRule = '||example.com/vast/$important,redirect=empty,~thirt-party';
expectedUboRule = '||example.com/vast/$important,redirect=empty,~thirt-party';
assert.strictEqual(convertAdgRedirectToUbo(adgRule), expectedUboRule);

assert.throws(() => {
adgRule = '||example.com/ad/vmap/*$xmlhttprequest,redirect=noopvast-2.0';
convertAdgRedirectToUbo(adgRule);
}, 'unable to convert -- no such ubo redirect');

assert.throws(() => {
adgRule = '||example.com/ad/vmap/*$redirect=nooptext';
convertAdgRedirectToUbo(adgRule);
}, 'unable to convert -- no source type specified');
});
Loading