[Pkg-mozext-commits] [requestpolicy] 197/257: [imp] old rules: detect errors in the pref strings
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:20:12 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit aaea07ef090172a670ea2b5b9286ebc100c391af
Author: Martin Kimmerle <dev at 256k.de>
Date: Sun Dec 6 01:45:41 2015 +0100
[imp] old rules: detect errors in the pref strings
---
src/content/lib/old-rules.jsm | 34 +++++++++++++++++++++++++++-------
tests/xpcshell/test_oldrules.js | 41 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 67 insertions(+), 8 deletions(-)
diff --git a/src/content/lib/old-rules.jsm b/src/content/lib/old-rules.jsm
index 9eedb21..6c10bb2 100644
--- a/src/content/lib/old-rules.jsm
+++ b/src/content/lib/old-rules.jsm
@@ -24,8 +24,8 @@
/* global Components */
const {interfaces: Ci, results: Cr, utils: Cu} = Components;
-/* exported OldRules */
-this.EXPORTED_SYMBOLS = ["OldRules"];
+/* exported OldRules, OldRulesParseError */
+this.EXPORTED_SYMBOLS = ["OldRules", "OldRulesParseError"];
let {ScriptLoader: {importModule}} = Cu.import(
"chrome://rpcontinued/content/lib/script-loader.jsm", {});
@@ -114,12 +114,20 @@ var OldRules = (function() {
}
for (let originToDest of originsToDests) {
- let [origin, dest] = originToDest.split("|");
+ let parts = originToDest.split("|");
+
+ if (parts.length === 2) {
+ let [origin, dest] = parts;
+ if (origin !== "" && dest !== "") {
+ rules.push({
+ o: OldRules.getEndpointSpecFromString(origin, addHostWildcard),
+ d: OldRules.getEndpointSpecFromString(dest, addHostWildcard)
+ });
+ continue;
+ }
+ }
- rules.push({
- o: OldRules.getEndpointSpecFromString(origin, addHostWildcard),
- d: OldRules.getEndpointSpecFromString(dest, addHostWildcard)
- });
+ throw new OldRulesParseError(`Invalid old rule: "${originToDest}"`);
}
return rules;
@@ -177,3 +185,15 @@ var OldRules = (function() {
return OldRules;
}());
+
+//==============================================================================
+// ParseError
+//==============================================================================
+
+function OldRulesParseError() {
+ Error.apply(this, arguments);
+ this.name = 'OldRulesParseError';
+}
+
+OldRulesParseError.prototype = Object.create(Error.prototype);
+OldRulesParseError.prototype.constructor = Error;
diff --git a/tests/xpcshell/test_oldrules.js b/tests/xpcshell/test_oldrules.js
index ebc8995..ea30ea0 100644
--- a/tests/xpcshell/test_oldrules.js
+++ b/tests/xpcshell/test_oldrules.js
@@ -1,7 +1,7 @@
/* exported run_test */
/* global Cc, Ci, Cu, equal, deepEqual */
-/* global OldRules */
+/* global OldRules, OldRulesParseError */
Cu.import("chrome://rpcontinued/content/lib/old-rules.jsm");
/* global rpPrefBranch */
Cu.import("chrome://rpcontinued/content/lib/prefs.jsm");
@@ -12,6 +12,7 @@ function run_test() {
test_0();
test_1();
+ test_2();
}
@@ -118,6 +119,44 @@ function test_1() {
}
+/**
+ * Special cases.
+ */
+function test_2() {
+ "use strict";
+
+ // invalid rules
+
+ function testInvalidRule(originToDest) {
+ Assert.throws(function() {
+ testGetOldRulesAsNewRules(["", "", originToDest], []);
+ }, OldRulesParseError);
+ }
+
+ testInvalidRule("|");
+ testInvalidRule("zeroVerticalBars");
+ testInvalidRule("multiple|vertical|bars");
+ testInvalidRule("foo|");
+ testInvalidRule("|bar");
+ testInvalidRule("|foobar|");
+
+ // many spaces
+
+ testGetOldRulesAsNewRules(
+ [
+ "a b",
+ " c d ",
+ " e|f g|h "
+ ],
+ [
+ {o: {h: "*.a"}}, {o: {h: "*.b"}},
+ {d: {h: "*.c"}}, {d: {h: "*.d"}},
+ {o: {h: "*.e"}, d: {h: "*.f"}},
+ {o: {h: "*.g"}, d: {h: "*.h"}}
+ ]);
+}
+
+
function usingOldRulePrefs(aPrefs, aFunction) {
"use strict";
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list