[Pkg-mozext-commits] [requestpolicy] 254/280: bugfix: URIs without host in `Rule.isMatch()`
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:36 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 51245a3aa8b83af4594887f5a1dd56316a7b6674
Author: Martin Kimmerle <dev at 256k.de>
Date: Tue Apr 28 11:02:55 2015 +0200
bugfix: URIs without host in `Rule.isMatch()`
Rule.isMatch() now can handle URIs without host
---
src/content/lib/ruleset.jsm | 36 +++++++++++++++++++++---------------
src/content/lib/utils/domains.jsm | 28 +++++++++++++++++++++-------
2 files changed, 42 insertions(+), 22 deletions(-)
diff --git a/src/content/lib/ruleset.jsm b/src/content/lib/ruleset.jsm
index 56fabed..ff7fac1 100644
--- a/src/content/lib/ruleset.jsm
+++ b/src/content/lib/ruleset.jsm
@@ -601,31 +601,37 @@ Rule.prototype = {
isMatch : function(uriObj) {
if (this.scheme && this.scheme != uriObj.scheme) {
- dprint("isMatch: wrong scheme");
+ //dprint("isMatch: wrong scheme (uri: '" + uriObj.scheme + "', rule: '" +
+ // this.scheme + "')");
return false;
}
- if (this.port) {
- // If the rule's port is "*" it means any port. We use this convention
- // because we assume an empty port in a rule means default ports rather
- // than any port.
- if (this.port != uriObj.port && this.port != "*") {
- dprint("isMatch: wrong port (not the port specified by the rule)");
- return false;
- }
- } else {
- if (!DomainUtil.hasStandardPort(uriObj)) {
- dprint("isMatch: wrong port (not the default port and the rule assumes default)");
- return false;
+
+ // Check the port only in case the URI has a host at all.
+ if (DomainUtil.uriObjHasHost(uriObj)) {
+ if (this.port) {
+ // If the rule's port is "*" it means any port. We use this convention
+ // because we assume an empty port in a rule means default ports rather
+ // than any port.
+ if (this.port !== uriObj.port && this.port !== "*") {
+ //dprint("isMatch: wrong port (not the port specified by the rule)");
+ return false;
+ }
+ } else {
+ if (!DomainUtil.hasStandardPort(uriObj)) {
+ //dprint("isMatch: wrong port (not the default port and the rule assumes default)");
+ return false;
+ }
}
}
+
if (this.path) {
if (typeof this.path == "string") {
if (uriObj.path.indexOf(this.path) != 0) {
- dprint("isMatch: wrong path (string): " + this.path + " vs " + uriObj.path);
+ //dprint("isMatch: wrong path (string): " + this.path + " vs " + uriObj.path);
return false;
}
} else if (!this.path.test(uriObj.path)) {
- dprint("isMatch: wrong path (regex)");
+ //dprint("isMatch: wrong path (regex)");
return false;
}
}
diff --git a/src/content/lib/utils/domains.jsm b/src/content/lib/utils/domains.jsm
index 690bb2c..585bbfb 100644
--- a/src/content/lib/utils/domains.jsm
+++ b/src/content/lib/utils/domains.jsm
@@ -107,18 +107,32 @@ DomainUtil.getIdentifier = function(uri, level) {
/**
* Returns the hostname from a uri string.
*
- * @param {String}
- * uri The uri.
- * @return {String} The hostname of the uri or throws an exception if it is an
- * invalid uri.
+ * @param {string} uri
+ * @return {?string} The hostname of the uri.
*/
DomainUtil.getHost = function(uri) {
let uriObj = this.getUriObject(uri);
- try {
+
+ if (DomainUtil.uriObjHasHost(uriObj)) {
return uriObj.host;
- } catch(e) {
+ }
+
+ // it's an URI without host
+ return null;
+};
+
+/**
+ * @param {nsIURI} aUriObj
+ * @return {boolean} whether the uri object has a host
+ */
+DomainUtil.uriObjHasHost = function(aUriObj) {
+ try {
+ // simply access the host.
+ aUriObj.host;
+ return true;
+ } catch (e) {
// it's an URI without host
- return null;
+ return false;
}
};
--
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