]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Protect array for/in loops 8686/head
authorKevin Ball <kmball11@gmail.com>
Wed, 27 Apr 2016 16:32:07 +0000 (09:32 -0700)
committerKevin Ball <kmball11@gmail.com>
Wed, 27 Apr 2016 16:32:07 +0000 (09:32 -0700)
js/foundation.interchange.js
js/foundation.util.mediaQuery.js

index bc0f6ada97c2fce59798b7bfe60ac88416221ce8..1a15ff01a35962c6911575ddf4e84e4e542cc2ce 100644 (file)
@@ -59,10 +59,12 @@ class Interchange {
 
     // Iterate through each rule, but only save the last match
     for (var i in this.rules) {
-      var rule = this.rules[i];
+      if(this.rules.hasOwnProperty(i)) {
+        var rule = this.rules[i];
 
-      if (window.matchMedia(rule.query).matches) {
-        match = rule;
+        if (window.matchMedia(rule.query).matches) {
+          match = rule;
+        }
       }
     }
 
@@ -78,8 +80,10 @@ class Interchange {
    */
   _addBreakpoints() {
     for (var i in Foundation.MediaQuery.queries) {
-      var query = Foundation.MediaQuery.queries[i];
-      Interchange.SPECIAL_QUERIES[query.name] = query.value;
+      if (Foundation.MediaQuery.queries.hasOwnProperty(i)) {
+        var query = Foundation.MediaQuery.queries[i];
+        Interchange.SPECIAL_QUERIES[query.name] = query.value;
+      }
     }
   }
 
@@ -102,18 +106,20 @@ class Interchange {
     }
 
     for (var i in rules) {
-      var rule = rules[i].slice(1, -1).split(', ');
-      var path = rule.slice(0, -1).join('');
-      var query = rule[rule.length - 1];
-
-      if (Interchange.SPECIAL_QUERIES[query]) {
-        query = Interchange.SPECIAL_QUERIES[query];
+      if(rules.hasOwnProperty(i)) {
+        var rule = rules[i].slice(1, -1).split(', ');
+        var path = rule.slice(0, -1).join('');
+        var query = rule[rule.length - 1];
+
+        if (Interchange.SPECIAL_QUERIES[query]) {
+          query = Interchange.SPECIAL_QUERIES[query];
+        }
+
+        rulesList.push({
+          path: path,
+          query: query
+        });
       }
-
-      rulesList.push({
-        path: path,
-        query: query
-      });
     }
 
     this.rules = rulesList;
index baa1f0b8721c69adca213ed737a0271aae7396cc..b9fe5b44a24afe3e2fecc4a7209ad4bee8b12818 100644 (file)
@@ -33,10 +33,12 @@ var MediaQuery = {
     namedQueries = parseStyleToObject(extractedStyles);
 
     for (var key in namedQueries) {
-      self.queries.push({
-        name: key,
-        value: `only screen and (min-width: ${namedQueries[key]})`
-      });
+      if(namedQueries.hasOwnProperty(key)) {
+        self.queries.push({
+          name: key,
+          value: `only screen and (min-width: ${namedQueries[key]})`
+        });
+      }
     }
 
     this.current = this._getCurrentSize();
@@ -68,8 +70,10 @@ var MediaQuery = {
    */
   get(size) {
     for (var i in this.queries) {
-      var query = this.queries[i];
-      if (size === query.name) return query.value;
+      if(this.queries.hasOwnProperty(i)) {
+        var query = this.queries[i];
+        if (size === query.name) return query.value;
+      }
     }
 
     return null;