From af0d0f3afdc7eae5d4ca9a9fa4eee832e3c59bec Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Fri, 10 Jun 2016 10:55:19 -0400
Subject: [PATCH] guard-for-in

---
 themes/bootstrap3/js/cart.js                |  4 ++-
 themes/bootstrap3/js/check_save_statuses.js | 22 ++++++------
 themes/bootstrap3/js/common.js              |  4 ++-
 themes/bootstrap3/js/hierarchyTree.js       |  6 ++--
 themes/bootstrap3/js/preview.js             | 40 +++++++++++----------
 5 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/themes/bootstrap3/js/cart.js b/themes/bootstrap3/js/cart.js
index fbc1ef063dd..6e3e1fc7f46 100644
--- a/themes/bootstrap3/js/cart.js
+++ b/themes/bootstrap3/js/cart.js
@@ -208,7 +208,9 @@ VuFind.register('cart', function Cart() {
 function cartFormHandler(event, data) {
   var keys = [];
   for (var i in data) {
-    keys.push(data[i].name);
+    if (data.hasOwnProperty(i)) {
+      keys.push(data[i].name);
+    }
   }
   if (keys.indexOf('ids[]') === -1) {
     return null;
diff --git a/themes/bootstrap3/js/check_save_statuses.js b/themes/bootstrap3/js/check_save_statuses.js
index a13c5fa31a6..2a9d1ec8ea5 100644
--- a/themes/bootstrap3/js/check_save_statuses.js
+++ b/themes/bootstrap3/js/check_save_statuses.js
@@ -37,17 +37,19 @@ function checkSaveStatuses(_container) {
     })
     .done(function checkSaveStatusDone(response) {
       for (var sel in response.data) {
-        var list = elements[sel];
-        if (!list) {
-          list = $('.savedLists');
+        if (response.data.hasOwnProperty(sel)) {
+          var list = elements[sel];
+          if (!list) {
+            list = $('.savedLists');
+          }
+          var html = list.find('strong')[0].outerHTML + '<ul>';
+          for (var i = 0; i < response.data[sel].length; i++) {
+            html += '<li><a href="' + response.data[sel][i].list_url + '">'
+              + htmlEncode(response.data[sel][i].list_title) + '</a></li>';
+          }
+          html += '</ul>';
+          list.html(html).removeClass('hidden');
         }
-        var html = list.find('strong')[0].outerHTML + '<ul>';
-        for (var i = 0; i < response.data[sel].length; i++) {
-          html += '<li><a href="' + response.data[sel][i].list_url + '">'
-            + htmlEncode(response.data[sel][i].list_title) + '</a></li>';
-        }
-        html += '</ul>';
-        list.html(html).removeClass('hidden');
       }
     });
   }
diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js
index 72826c1f1bb..41e07f33b56 100644
--- a/themes/bootstrap3/js/common.js
+++ b/themes/bootstrap3/js/common.js
@@ -32,7 +32,9 @@ var VuFind = (function VuFind() {
 
   var addTranslations = function addTranslations(s) {
     for (var i in s) {
-      _translations[i] = s[i];
+      if (s.hasOwnProperty(i)) {
+        _translations[i] = s[i];
+      }
     }
   };
   var translate = function translate(op) {
diff --git a/themes/bootstrap3/js/hierarchyTree.js b/themes/bootstrap3/js/hierarchyTree.js
index 70ab809310b..4035c78d77c 100644
--- a/themes/bootstrap3/js/hierarchyTree.js
+++ b/themes/bootstrap3/js/hierarchyTree.js
@@ -15,8 +15,10 @@ function html_entity_decode(string) {
   var tmp_str = string.toString();
 
   for (var symbol in hash_map) {
-    var entity = hash_map[symbol];
-    tmp_str = tmp_str.split(entity).join(symbol);
+    if (hash_map.hasOwnProperty(symbol)) {
+      var entity = hash_map[symbol];
+      tmp_str = tmp_str.split(entity).join(symbol);
+    }
   }
   tmp_str = tmp_str.split('&#039;').join("'");
 
diff --git a/themes/bootstrap3/js/preview.js b/themes/bootstrap3/js/preview.js
index 37ef7f531b1..1d9c0b716d0 100644
--- a/themes/bootstrap3/js/preview.js
+++ b/themes/bootstrap3/js/preview.js
@@ -8,8 +8,10 @@ function getGoogleOptions() {
   var opts_temp = $('[class*="googlePreviewSpan"]').attr("class").split('__')[1].split(';');
   var options = {};
   for (var key in opts_temp) {
-    var arr = opts_temp[key].split(':');
-    options[arr[0]] = arr[1].split(',');
+    if (opts_temp.hasOwnProperty(key)) {
+      var arr = opts_temp[key].split(':');
+      options[arr[0]] = arr[1].split(',');
+    }
   }
   return options;
 }
@@ -46,12 +48,11 @@ function applyPreviewUrl($link, url) {
 
 function processBookInfo(booksInfo, previewClass, viewOptions) {
   for (var bibkey in booksInfo) {
-    var bookInfo = booksInfo[bibkey];
-    if (bookInfo) {
-      if (viewOptions.indexOf(bookInfo.preview) >= 0) {
+    if (bookInfo[bibkey]) {
+      if (viewOptions.indexOf(bookInfo[bibkey].preview) >= 0) {
         applyPreviewUrl(
-                    $('.' + previewClass + '.' + bibkey), bookInfo.preview_url
-                );
+          $('.' + previewClass + '.' + bibkey), bookInfo[bibkey].preview_url
+        );
       }
     }
   }
@@ -65,11 +66,10 @@ function processGBSBookInfo(booksInfo) {
   if (viewOptions.tab && viewOptions.tab.length > 0) {
         // check for "embeddable: true" in bookinfo
     for (var bibkey in booksInfo) {
-      var bookInfo = booksInfo[bibkey];
-      if (bookInfo) {
-        if (viewOptions.tab.indexOf(bookInfo.preview) >= 0
-                && (bookInfo.embeddable)) {
-                    // make tab visible
+      if (bookInfo[bibkey]) {
+        if (viewOptions.tab.indexOf(bookInfo[bibkey].preview) >= 0
+        && (bookInfo[bibkey].embeddable)) {
+          // make tab visible
           $('ul.nav-tabs li.hidden a.preview').parent().removeClass('hidden');
         }
       }
@@ -83,13 +83,15 @@ function processOLBookInfo(booksInfo) {
 
 function processHTBookInfo(booksInfo) {
   for (var b in booksInfo) {
-    var bibkey = b.replace(/:/, '').toUpperCase();
-    var $link = $('.previewHT.' + bibkey);
-    var items = booksInfo[b].items;
-    for (var i = 0; i < items.length; i++) {
-            // check if items possess an eligible rights code
-      if (getHathiOptions().indexOf(items[i].rightsCode) >= 0) {
-        applyPreviewUrl($link, items[i].itemURL);
+    if (booksInfo.hasOwnProperty(b)) {
+      var bibkey = b.replace(/:/, '').toUpperCase();
+      var $link = $('.previewHT.' + bibkey);
+      var items = booksInfo[b].items;
+      for (var i = 0; i < items.length; i++) {
+        // check if items possess an eligible rights code
+        if (getHathiOptions().indexOf(items[i].rightsCode) >= 0) {
+          applyPreviewUrl($link, items[i].itemURL);
+        }
       }
     }
   }
-- 
GitLab