1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-22 02:12:44 +01:00

Fix npm test suite

Ensure serialization returns copy of data rather than live
references to data. This allows to immediately deserialize() the
result of serialize().

Also, adjust code to modified behavior of filterQuery().
This commit is contained in:
Raymond Hill 2024-10-05 11:32:59 -04:00
parent 3b53d8e5b7
commit 41693407b2
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 65 additions and 64 deletions

View File

@ -218,6 +218,7 @@ class StaticNetFilteringEngine {
}
filterQuery(details) {
fctx.redirectURL = undefined;
const directives = snfe.filterQuery(fctx.fromDetails(details));
if ( directives === undefined ) { return; }
return { redirectURL: fctx.redirectURL, directives };

View File

@ -242,12 +242,15 @@
}
},
"node_modules/braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
"dev": true,
"dependencies": {
"fill-range": "^7.0.1"
"fill-range": "^7.1.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/browser-stdout": {
@ -683,12 +686,15 @@
}
},
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
"dev": true,
"dependencies": {
"to-regex-range": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/find-up": {
@ -892,7 +898,10 @@
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
"dev": true
"dev": true,
"engines": {
"node": ">=0.12.0"
}
},
"node_modules/is-path-inside": {
"version": "3.0.3",
@ -1062,15 +1071,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/make-dir/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@ -1398,6 +1398,15 @@
"resolved": "git+ssh://git@github.com/mjethani/scaling-palm-tree.git#15cf1ab37e038771e1ff8005edc46d95f176739f",
"dev": true
},
"node_modules/semver": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/serialize-javascript": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
@ -1481,6 +1490,9 @@
"dev": true,
"dependencies": {
"is-number": "^7.0.0"
},
"engines": {
"node": ">=8.0"
}
},
"node_modules/type-check": {
@ -1537,10 +1549,13 @@
}
},
"node_modules/word-wrap": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
"dev": true
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz",
"integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/workerpool": {
"version": "6.2.1",
@ -1818,12 +1833,12 @@
}
},
"braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
"dev": true,
"requires": {
"fill-range": "^7.0.1"
"fill-range": "^7.1.1"
}
},
"browser-stdout": {
@ -2202,9 +2217,9 @@
}
},
"fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
"dev": true,
"requires": {
"to-regex-range": "^5.0.1"
@ -2532,14 +2547,6 @@
"dev": true,
"requires": {
"semver": "^6.0.0"
},
"dependencies": {
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
}
}
},
"minimatch": {
@ -2808,6 +2815,12 @@
"dev": true,
"from": "scaling-palm-tree@github:mjethani/scaling-palm-tree#15cf1ab37e038771e1ff8005edc46d95f176739f"
},
"semver": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"dev": true
},
"serialize-javascript": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
@ -2935,9 +2948,9 @@
}
},
"word-wrap": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz",
"integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==",
"dev": true
},
"workerpool": {

View File

@ -582,12 +582,12 @@ class BidiTrieContainer {
}
toSelfie() {
const buf32 = this.buf32.subarray(0, this.buf32[CHAR1_SLOT] + 3 >>> 2);
const buf32 = this.buf32.slice(0, this.buf32[CHAR1_SLOT] + 3 >>> 2);
return { buf32, checksum: i32Checksum(buf32) };
}
fromSelfie(selfie) {
if ( selfie instanceof Object === false ) { return false; }
if ( typeof selfie !== 'object' || selfie === null ) { return false; }
if ( selfie.buf32 instanceof Uint32Array === false ) { return false; }
if ( selfie.checksum !== i32Checksum(selfie.buf32) ) { return false; }
const byteLength = selfie.buf32.length << 2;

View File

@ -452,12 +452,12 @@ class HNTrieContainer {
}
toSelfie() {
const buf32 = this.buf32.subarray(0, this.buf32[CHAR1_SLOT] + 3 >>> 2);
const buf32 = this.buf32.slice(0, this.buf32[CHAR1_SLOT] + 3 >>> 2);
return { buf32, checksum: i32Checksum(buf32) };
}
fromSelfie(selfie) {
if ( selfie instanceof Object === false ) { return false; }
if ( typeof selfie !== 'object' || selfie === null ) { return false; }
if ( selfie.buf32 instanceof Uint32Array === false ) { return false; }
if ( selfie.checksum !== i32Checksum(selfie.buf32) ) { return false; }
this.needle = '';

View File

@ -495,7 +495,7 @@ const filterDataReset = ( ) => {
filterDataWritePtr = 2;
};
const filterDataToSelfie = ( ) =>
filterData.subarray(0, filterDataWritePtr);
filterData.slice(0, filterDataWritePtr);
const filterDataFromSelfie = selfie => {
if ( selfie instanceof Int32Array === false ) { return false; }
@ -3193,7 +3193,7 @@ const urlTokenizer = new (class {
}
toSelfie() {
return this.knownTokens;
return this.knownTokens.slice();
}
fromSelfie(selfie) {
@ -4779,7 +4779,7 @@ StaticNetFilteringEngine.prototype.toSelfie = function() {
processedFilterCount: this.processedFilterCount,
acceptedCount: this.acceptedCount,
discardedCount: this.discardedCount,
bitsToBucket: this.bitsToBucket,
bitsToBucket: new Map(this.bitsToBucket),
urlTokenizer: urlTokenizer.toSelfie(),
destHNTrieContainer: destHNTrieContainer.toSelfie(),
origHNTrieContainer: origHNTrieContainer.toSelfie(),
@ -4789,20 +4789,13 @@ StaticNetFilteringEngine.prototype.toSelfie = function() {
};
};
StaticNetFilteringEngine.prototype.serialize = async function() {
const selfie = [];
const storage = {
put(name, data) {
selfie.push([ name, data ]);
}
};
await this.toSelfie(storage, '');
return JSON.stringify(selfie);
StaticNetFilteringEngine.prototype.serialize = function() {
return this.toSelfie();
};
/******************************************************************************/
StaticNetFilteringEngine.prototype.fromSelfie = async function(selfie) {
StaticNetFilteringEngine.prototype.fromSelfie = function(selfie) {
if ( typeof selfie !== 'object' || selfie === null ) { return; }
this.reset();
@ -4835,14 +4828,8 @@ StaticNetFilteringEngine.prototype.fromSelfie = async function(selfie) {
return true;
};
StaticNetFilteringEngine.prototype.unserialize = async function(s) {
const selfie = new Map(JSON.parse(s));
const storage = {
async get(name) {
return { content: selfie.get(name) };
}
};
return this.fromSelfie(storage, '');
StaticNetFilteringEngine.prototype.unserialize = function(selfie) {
return this.fromSelfie(selfie);
};
/******************************************************************************/