mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Add test to detect case of improper deserialization
Related commit:
- 8f461072f5
This commit is contained in:
parent
a7ef3300fe
commit
0bc0af9d8d
@ -218,6 +218,12 @@ class StaticNetFilteringEngine {
|
|||||||
return snfe.hasQuery(details);
|
return snfe.hasQuery(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filterQuery(details) {
|
||||||
|
const directives = snfe.filterQuery(fctx.fromDetails(details));
|
||||||
|
if ( directives === undefined ) { return; }
|
||||||
|
return { redirectURL: fctx.redirectURL, directives };
|
||||||
|
}
|
||||||
|
|
||||||
isBlockImportant() {
|
isBlockImportant() {
|
||||||
return snfe.isBlockImportant();
|
return snfe.isBlockImportant();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@gorhill/ubo-core",
|
"name": "@gorhill/ubo-core",
|
||||||
"version": "0.1.23",
|
"version": "0.1.24",
|
||||||
"description": "To create a working instance of uBlock Origin's static network filtering engine",
|
"description": "To create a working instance of uBlock Origin's static network filtering engine",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
@ -231,8 +231,25 @@ describe('SNFE', () => {
|
|||||||
const serialized = await engine.serialize();
|
const serialized = await engine.serialize();
|
||||||
await engine.deserialize(serialized);
|
await engine.deserialize(serialized);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/commit/8f461072f576cdf72c088a952ef342281a7c44d6
|
||||||
|
it('should correctly remove query parameter following deserialization', async () => {
|
||||||
|
await engine.useLists([
|
||||||
|
{ name: 'custom', raw: '*$removeparam=/^utm_/' },
|
||||||
|
]);
|
||||||
|
const request = {
|
||||||
|
originURL: 'https://www.example.com/?utm_source=1',
|
||||||
|
type: 'document',
|
||||||
|
url: 'https://www.example.com/?utm_source=1',
|
||||||
|
};
|
||||||
|
let result = engine.filterQuery(request);
|
||||||
|
assert.strictEqual(result.redirectURL, 'https://www.example.com/');
|
||||||
|
const serialized = await engine.serialize();
|
||||||
|
await engine.deserialize(serialized);
|
||||||
|
result = engine.filterQuery(request);
|
||||||
|
assert.strictEqual(result.redirectURL, 'https://www.example.com/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Filter matching', () => {
|
describe('Filter matching', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@ -440,7 +440,7 @@ function filterRefsToSelfie() {
|
|||||||
refs.push({ t: 2, v });
|
refs.push({ t: 2, v });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( v instanceof Object === false ) {
|
if ( typeof v !== 'object' || v === null ) {
|
||||||
refs.push({ t: 0, v });
|
refs.push({ t: 0, v });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -3772,13 +3772,9 @@ FilterContainer.prototype.optimize = function(throttle = 0) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
FilterContainer.prototype.toSelfie = function(storage, path) {
|
FilterContainer.prototype.toSelfie = async function(storage, path) {
|
||||||
if (
|
if ( typeof storage !== 'object' || storage === null ) { return; }
|
||||||
storage instanceof Object === false ||
|
if ( typeof storage.put !== 'function' ) { return; }
|
||||||
storage.put instanceof Function === false
|
|
||||||
) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
const bucketsToSelfie = ( ) => {
|
const bucketsToSelfie = ( ) => {
|
||||||
const selfie = [];
|
const selfie = [];
|
||||||
@ -3844,12 +3840,8 @@ FilterContainer.prototype.serialize = async function() {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
FilterContainer.prototype.fromSelfie = async function(storage, path) {
|
FilterContainer.prototype.fromSelfie = async function(storage, path) {
|
||||||
if (
|
if ( typeof storage !== 'object' || storage === null ) { return; }
|
||||||
storage instanceof Object === false ||
|
if ( typeof storage.get !== 'function' ) { return; }
|
||||||
storage.get instanceof Function === false
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
@ -3881,7 +3873,7 @@ FilterContainer.prototype.fromSelfie = async function(storage, path) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const details = results[0];
|
const details = results[0];
|
||||||
if ( details instanceof Object === false ) { return false; }
|
if ( typeof details !== 'object' || details === null ) { return false; }
|
||||||
if ( typeof details.content !== 'string' ) { return false; }
|
if ( typeof details.content !== 'string' ) { return false; }
|
||||||
if ( details.content === '' ) { return false; }
|
if ( details.content === '' ) { return false; }
|
||||||
let selfie;
|
let selfie;
|
||||||
@ -3889,7 +3881,7 @@ FilterContainer.prototype.fromSelfie = async function(storage, path) {
|
|||||||
selfie = JSON.parse(details.content);
|
selfie = JSON.parse(details.content);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
if ( selfie instanceof Object === false ) { return false; }
|
if ( typeof selfie !== 'object' || selfie === null ) { return false; }
|
||||||
if ( selfie.version !== this.selfieVersion ) { return false; }
|
if ( selfie.version !== this.selfieVersion ) { return false; }
|
||||||
this.processedFilterCount = selfie.processedFilterCount;
|
this.processedFilterCount = selfie.processedFilterCount;
|
||||||
this.acceptedCount = selfie.acceptedCount;
|
this.acceptedCount = selfie.acceptedCount;
|
||||||
@ -3900,7 +3892,6 @@ FilterContainer.prototype.fromSelfie = async function(storage, path) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FilterContainer.prototype.unserialize = async function(s) {
|
FilterContainer.prototype.unserialize = async function(s) {
|
||||||
const selfie = new Map(JSON.parse(s));
|
const selfie = new Map(JSON.parse(s));
|
||||||
const storage = {
|
const storage = {
|
||||||
|
Loading…
Reference in New Issue
Block a user