Skip to content

Commit 1c5464c

Browse files
committed
one more update
1 parent 7d4690e commit 1c5464c

4 files changed

Lines changed: 101 additions & 75 deletions

File tree

dist/cjs/scriptlets.cjs.js

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,34 +4170,41 @@ var isAbpRedirectCompatibleWithAdg = function isAbpRedirectCompatibleWithAdg(rul
41704170

41714171

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

4176-
var sourceTypes = ruleModifiers.filter(function (el) {
4177-
return VALID_SOURCE_TYPES.indexOf(el) > -1;
4178-
});
4179-
var isSourceTypeSpecified = sourceTypes.length > 0;
4180-
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;
4181-
4182-
if (isEmptyRedirect) {
4183-
if (isSourceTypeSpecified) {
4184-
var isValidType = sourceTypes.reduce(function (acc, sType) {
4185-
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
4186-
return type === sType;
4187-
});
4188-
return !!isEmptySupported && acc;
4189-
}, true);
4190-
return isValidType;
4191-
} // no source type for 'empty' is allowed
4177+
if (!isAdgRedirectCompatibleWithUbo(rule)) {
4178+
throw new Error("Unable to convert - unsupported by uBO redirect in rule: ".concat(rule));
4179+
} // if (isAdgRedirectCompatibleWithUbo(rule)) {
4180+
// if (isRedirectRuleByType(rule, 'ADG')) {
41924181

41934182

4194-
return true;
4195-
}
4183+
var ruleModifiers = parseModifiers(rule); // rule can have more than one source type modifier
41964184

4197-
return isSourceTypeSpecified;
4185+
var sourceTypes = ruleModifiers.filter(function (el) {
4186+
return VALID_SOURCE_TYPES.indexOf(el) > -1;
4187+
});
4188+
var isSourceTypeSpecified = sourceTypes.length > 0;
4189+
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;
4190+
4191+
if (isEmptyRedirect) {
4192+
if (isSourceTypeSpecified) {
4193+
var isValidType = sourceTypes.reduce(function (acc, sType) {
4194+
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
4195+
return type === sType;
4196+
});
4197+
return !!isEmptySupported && acc;
4198+
}, true);
4199+
return isValidType;
4200+
} // no source type for 'empty' is allowed
4201+
4202+
4203+
return true;
41984204
}
41994205

4200-
return false;
4206+
return isSourceTypeSpecified; // }
4207+
// return false;
42014208
};
42024209

42034210
var validator = {

dist/scriptlets.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,33 +4171,41 @@
41714171

41724172

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

4177-
var sourceTypes = ruleModifiers.filter(function (el) {
4178-
return VALID_SOURCE_TYPES.indexOf(el) > -1;
4179-
});
4180-
var isSourceTypeSpecified = sourceTypes.length > 0;
4181-
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;
4182-
4183-
if (isEmptyRedirect) {
4184-
if (isSourceTypeSpecified) {
4185-
var isValidType = sourceTypes.reduce(function (acc, sType) {
4186-
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
4187-
return type === sType;
4188-
});
4189-
return !!isEmptySupported && acc;
4190-
}, true);
4191-
return isValidType;
4192-
} // no source type for 'empty' is allowed
4178+
if (!isAdgRedirectCompatibleWithUbo(rule)) {
4179+
throw new Error("Unable to convert - unsupported by uBO redirect in rule: ".concat(rule));
4180+
} // if (isAdgRedirectCompatibleWithUbo(rule)) {
4181+
// if (isRedirectRuleByType(rule, 'ADG')) {
41934182

41944183

4195-
return true;
4196-
}
4184+
var ruleModifiers = parseModifiers(rule); // rule can have more than one source type modifier
41974185

4198-
return isSourceTypeSpecified;
4186+
var sourceTypes = ruleModifiers.filter(function (el) {
4187+
return VALID_SOURCE_TYPES.indexOf(el) > -1;
4188+
});
4189+
var isSourceTypeSpecified = sourceTypes.length > 0;
4190+
var isEmptyRedirect = ruleModifiers.indexOf("".concat(ADG_UBO_REDIRECT_MARKER).concat(EMPTY_REDIRECT_MARKER)) > -1;
4191+
4192+
if (isEmptyRedirect) {
4193+
if (isSourceTypeSpecified) {
4194+
var isValidType = sourceTypes.reduce(function (acc, sType) {
4195+
var isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES.find(function (type) {
4196+
return type === sType;
4197+
});
4198+
return !!isEmptySupported && acc;
4199+
}, true);
4200+
return isValidType;
4201+
} // no source type for 'empty' is allowed
4202+
4203+
4204+
return true;
41994205
}
4200-
return false; // throw new Error(`Unsupported Redirect in rule: ${rule}`);
4206+
4207+
return isSourceTypeSpecified; // }
4208+
// return false;
42014209
};
42024210

42034211
var validator = {

src/helpers/validator.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -347,33 +347,39 @@ const isAbpRedirectCompatibleWithAdg = (rule) => {
347347
* @returns {boolean}
348348
*/
349349
const hasValidContentType = (rule) => {
350-
if (isRedirectRuleByType(rule, 'ADG')) {
351-
const ruleModifiers = parseModifiers(rule);
352-
// rule can have more than one source type modifier
353-
const sourceTypes = ruleModifiers
354-
.filter((el) => VALID_SOURCE_TYPES.indexOf(el) > -1);
355-
356-
const isSourceTypeSpecified = sourceTypes.length > 0;
357-
const isEmptyRedirect = ruleModifiers.indexOf(`${ADG_UBO_REDIRECT_MARKER}${EMPTY_REDIRECT_MARKER}`) > -1;
358-
359-
if (isEmptyRedirect) {
360-
if (isSourceTypeSpecified) {
361-
const isValidType = sourceTypes.reduce((acc, sType) => {
362-
const isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES
363-
.find((type) => type === sType);
364-
return !!isEmptySupported && acc;
365-
}, true);
366-
return isValidType;
367-
}
368-
// no source type for 'empty' is allowed
369-
return true;
370-
}
350+
if (!isRedirectRuleByType(rule, 'ADG')) {
351+
throw new Error(`Unable to convert - not an ADG rule: ${rule}`);
352+
}
353+
if (!isAdgRedirectCompatibleWithUbo(rule)) {
354+
throw new Error(`Unable to convert - unsupported by uBO redirect in rule: ${rule}`);
355+
}
371356

372-
return isSourceTypeSpecified;
357+
// if (isAdgRedirectCompatibleWithUbo(rule)) {
358+
// if (isRedirectRuleByType(rule, 'ADG')) {
359+
const ruleModifiers = parseModifiers(rule);
360+
// rule can have more than one source type modifier
361+
const sourceTypes = ruleModifiers
362+
.filter((el) => VALID_SOURCE_TYPES.indexOf(el) > -1);
363+
364+
const isSourceTypeSpecified = sourceTypes.length > 0;
365+
const isEmptyRedirect = ruleModifiers.indexOf(`${ADG_UBO_REDIRECT_MARKER}${EMPTY_REDIRECT_MARKER}`) > -1;
366+
367+
if (isEmptyRedirect) {
368+
if (isSourceTypeSpecified) {
369+
const isValidType = sourceTypes.reduce((acc, sType) => {
370+
const isEmptySupported = EMPTY_REDIRECT_SUPPORTED_TYPES
371+
.find((type) => type === sType);
372+
return !!isEmptySupported && acc;
373+
}, true);
374+
return isValidType;
375+
}
376+
// no source type for 'empty' is allowed
377+
return true;
373378
}
374379

375-
return false;
376-
// throw new Error(`Unsupported Redirect in rule: ${rule}`);
380+
return isSourceTypeSpecified;
381+
// }
382+
// return false;
377383
};
378384

379385
const validator = {

tests/lib-tests/index.test.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ test('Test redirect rule validation', (assert) => {
174174
// invalid redirect name
175175
inputRule = '||example.orf^$media,redirect=no-mp4';
176176
assert.strictEqual(validator.isAdgRedirectCompatibleWithUbo(inputRule), false);
177+
// no ubo analog for redirect
178+
inputRule = '||example.com/ad/vmap/*$xmlhttprequest,redirect=noopvmap-1.0';
179+
assert.strictEqual(validator.isAdgRedirectCompatibleWithUbo(inputRule), false);
177180
// rules with 'redirect=' marker in base rule part should be skipped
178181
inputRule = '_redirect=*://look.$popup';
179182
assert.strictEqual(validator.isAdgRedirectCompatibleWithUbo(inputRule), false);
@@ -247,9 +250,11 @@ test('Test redirect rule validation for ADG -> UBO converting', (assert) => {
247250
adgRule = '||example.com/images/*.png$image,important,redirect=1x1-transparent.gif,domain=example.com|example.org';
248251
assert.strictEqual(validator.hasValidContentType(adgRule), true);
249252

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

254259
// no source type
255260
adgRule = '||example.com^$important,redirect=nooptext';
@@ -280,10 +285,10 @@ test('Test REDIRECT converting - ADG -> UBO', (assert) => {
280285
expectedUboRule = '||example.com/vast/$important,redirect=empty,~thirt-party';
281286
assert.strictEqual(convertAdgRedirectToUbo(adgRule), expectedUboRule);
282287

283-
// assert.throws(() => {
284-
// adgRule = '||example.com/ad/vmap/*$xmlhttprequest,redirect=noopvast-2.0';
285-
// convertAdgRedirectToUbo(adgRule);
286-
// }, 'unable to convert -- no such ubo redirect');
288+
assert.throws(() => {
289+
adgRule = '||example.com/ad/vmap/*$xmlhttprequest,redirect=noopvast-2.0';
290+
convertAdgRedirectToUbo(adgRule);
291+
}, 'unable to convert -- no such ubo redirect');
287292

288293
assert.throws(() => {
289294
adgRule = '||example.com/ad/vmap/*$redirect=nooptext';

0 commit comments

Comments
 (0)