[Pkg-mozext-commits] [requestpolicy] 131/257: [ref] merge `ruleDataPartToDisplayString` functions

David Prévot taffit at moszumanska.debian.org
Thu Jan 28 03:20:05 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 a0bc3855558ff1fee545afd26e45af21488869e0
Author: Martin Kimmerle <dev at 256k.de>
Date:   Sat May 23 19:47:31 2015 +0200

    [ref] merge `ruleDataPartToDisplayString` functions
---
 src/content/settings/common.js     | 42 +++++++++++++++++++++++++++++++++++
 src/content/settings/oldrules.js   | 17 ++------------
 src/content/settings/yourpolicy.js | 45 ++------------------------------------
 3 files changed, 46 insertions(+), 58 deletions(-)

diff --git a/src/content/settings/common.js b/src/content/settings/common.js
index 9d682dd..582fdc8 100644
--- a/src/content/settings/common.js
+++ b/src/content/settings/common.js
@@ -88,6 +88,48 @@ common.switchSubscriptionPolicies = function () {
   }
 };
 
+/**
+ * Get a string representation of an endpoint (origin or dest) specification.
+ *
+ * The following list shows a mapping of the possible endpoint specs
+ * to the corresponding string representation. Each endpoint spec contains at
+ * least one of the parts "scheme", "host" and "port". The list shows the
+ * strings by example: scheme "http"; host "www.example.com"; port "80".
+ *
+ * - s__: `scheme "http"`
+ * - _h_: `www.example.com`
+ * - __p: `*://*:80`
+ * - sh_: `http://www.example.com`
+ * - s_p: `http://*:80`
+ * - _hp: `*://www.example.com:80`
+ * - shp: `http://www.example.com:80`
+ *
+ * TODO: remove code duplication with menu.js
+ */
+common.ruleDataPartToDisplayString = function (ruleDataPart) {
+  if (ruleDataPart["s"] && !ruleDataPart["h"] && !ruleDataPart["port"]) {
+    // Special case: Only a scheme is specified.
+    //               The result string will be `scheme "..."`.
+    // Background info: The string could be `http:*`, but this could however
+    //                  be confused with `*://http:*`. The string `http://*`
+    //                  wouldn't be correct for all cases, since there are
+    //                  URIs _without_ a host.
+    return "scheme \"" + ruleDataPart["s"] + "\"";
+  }
+  var str = "";
+  if (ruleDataPart["s"] || ruleDataPart["port"]) {
+    str += ruleDataPart["s"] || "*";
+    str += "://";
+  }
+  str += ruleDataPart["h"] || "*";
+  if (ruleDataPart["port"]) {
+    str += ":" + ruleDataPart["port"];
+  }
+  // TODO: path
+  return str;
+};
+
+
 common.getOldRulesAsNewRules = function (addHostWildcard) {
   var origins = common.getPrefObj('allowedOrigins');
   var destinations = common.getPrefObj('allowedDestinations');
diff --git a/src/content/settings/oldrules.js b/src/content/settings/oldrules.js
index 1f2c1d0..4784657 100644
--- a/src/content/settings/oldrules.js
+++ b/src/content/settings/oldrules.js
@@ -33,8 +33,8 @@ function populateRuleTable() {
 
   for (var i = 0; i < rules.length; i++) {
     var entry = rules[i];
-    var origin = entry['o'] ? ruleDataPartToDisplayString(entry['o']) : '';
-    var dest = entry['d'] ? ruleDataPartToDisplayString(entry['d']) : '';
+    var origin = entry['o'] ? common.ruleDataPartToDisplayString(entry['o']) : '';
+    var dest = entry['d'] ? common.ruleDataPartToDisplayString(entry['d']) : '';
     addRulesTableRow(table, 'allow', origin, dest, entry);
   }
 }
@@ -52,19 +52,6 @@ function addRulesTableRow(table, ruleAction, origin, dest, ruleData) {
   );
 }
 
-// TODO: remove code duplication with menu.js
-function ruleDataPartToDisplayString(ruleDataPart) {
-  var str = "";
-  if (ruleDataPart["s"]) {
-    str += ruleDataPart["s"] + "://";
-  }
-  str += ruleDataPart["h"] || "*";
-  if (ruleDataPart["port"]) {
-    str += ":" + ruleDataPart["port"];
-  }
-  return str;
-}
-
 function deleteOldRules() {
   common.clearPref('allowedOrigins');
   common.clearPref('allowedDestinations');
diff --git a/src/content/settings/yourpolicy.js b/src/content/settings/yourpolicy.js
index 9ca80d6..810e3a8 100644
--- a/src/content/settings/yourpolicy.js
+++ b/src/content/settings/yourpolicy.js
@@ -65,8 +65,8 @@ function addRules(entries, source, filter, readOnly) {
   for (var entryType in entries) {
     for (var i = 0; i < entries[entryType].length; i++) {
       var entry = entries[entryType][i];
-      var origin = entry['o'] ? ruleDataPartToDisplayString(entry['o']) : '';
-      var dest = entry['d'] ? ruleDataPartToDisplayString(entry['d']) : '';
+      var origin = entry['o'] ? common.ruleDataPartToDisplayString(entry['o']) : '';
+      var dest = entry['d'] ? common.ruleDataPartToDisplayString(entry['d']) : '';
       if (filter) {
         if (origin.indexOf(filter) == -1 && dest.indexOf(filter) == -1) {
           continue;
@@ -130,47 +130,6 @@ function addRulesTableRow(table, ruleAction, origin, dest, ruleData, source, rea
   }
 }
 
-/**
- * Get a string representation of an endpoint (origin or dest) specification.
- *
- * The following list shows a mapping of the possible endpoint specs
- * to the corresponding string representation. Each endpoint spec contains at
- * least one of the parts "scheme", "host" and "port". The list shows the
- * strings by example: scheme "http"; host "www.example.com"; port "80".
- *
- * - s__: `scheme "http"`
- * - _h_: `www.example.com`
- * - __p: `*://*:80`
- * - sh_: `http://www.example.com`
- * - s_p: `http://*:80`
- * - _hp: `*://www.example.com:80`
- * - shp: `http://www.example.com:80`
- *
- * TODO: remove code duplication with menu.js
- */
-function ruleDataPartToDisplayString(ruleDataPart) {
-  if (ruleDataPart["s"] && !ruleDataPart["h"] && !ruleDataPart["port"]) {
-    // Special case: Only a scheme is specified.
-    //               The result string will be `scheme "..."`.
-    // Background info: The string could be `http:*`, but this could however
-    //                  be confused with `*://http:*`. The string `http://*`
-    //                  wouldn't be correct for all cases, since there are
-    //                  URIs _without_ a host.
-    return "scheme \"" + ruleDataPart["s"] + "\"";
-  }
-  var str = "";
-  if (ruleDataPart["s"] || ruleDataPart["port"]) {
-    str += ruleDataPart["s"] || "*";
-    str += "://";
-  }
-  str += ruleDataPart["h"] || "*";
-  if (ruleDataPart["port"]) {
-    str += ":" + ruleDataPart["port"];
-  }
-  // TODO: path
-  return str;
-}
-
 function addRule() {
   try {
     addRuleHelper();

-- 
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