summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbdealiJK <abdealikothari@gmail.com>2020-02-25 01:06:31 +0530
committerNed Batchelder <ned@nedbatchelder.com>2020-02-29 08:08:08 -0500
commit48c73b88bf2f3a5cdb404b20afa34cb2cb940e0f (patch)
treedf14701bd8e89bb947c7585abc5f86b35259a4b4
parent0f82d27e07e96ce3e840779e8bd8c53a1ed34eea (diff)
downloadpython-coveragepy-git-48c73b88bf2f3a5cdb404b20afa34cb2cb940e0f.tar.gz
htmlfiles: Handle localStorage not accessible
In some cases, if based on the browser's settings - localStorage is not accessible, fallback and don't save the sort-columns into localStorage. While the UX is a little inconvenient, at least the page doesn't break - sorting on columns is still possible, but not retained between pages.
-rw-r--r--CHANGES.rst6
-rw-r--r--CONTRIBUTORS.txt1
-rw-r--r--coverage/htmlfiles/coverage_html.js9
3 files changed, 14 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 6efe083c..37c0ddf6 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -30,7 +30,13 @@ Unreleased
- Windows 3.8 wheels were incorrectly built, but are now fixed. (`issue 949`_)
+- HTML report couldn't be sorted if localStorage wasn't available. This is now
+ fixed: sorting works even though the sorting setting isn't retained. (`issue
+ 944`_ and `pull request 945`_). Thanks, Abdeali Kothari.
+
.. _issue 943: https://github.com/nedbat/coveragepy/issues/943
+.. _issue 944: https://github.com/nedbat/coveragepy/issues/944
+.. _pull request 945: https://github.com/nedbat/coveragepy/pull/945
.. _issue 949: https://github.com/nedbat/coveragepy/issues/949
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 65919f1e..a89c3bfa 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -4,6 +4,7 @@ extended and maintained by Ned Batchelder.
Other contributions, including writing code, updating docs, and submitting
useful bug reports, have been made by:
+Abdeali Kothari
Adi Roiban
Agbonze O. Jeremiah
Albertas Agejevas
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index 22152333..3bf04bf9 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -172,7 +172,10 @@ coverage.index_ready = function ($) {
// Look for a localStorage item containing previous sort settings:
var sort_list = [];
var storage_name = "COVERAGE_INDEX_SORT";
- var stored_list = localStorage.getItem(storage_name);
+ var stored_list = undefined;
+ try {
+ stored_list = localStorage.getItem(storage_name);
+ } catch(err) {}
if (stored_list) {
sort_list = JSON.parse('[[' + stored_list + ']]');
@@ -222,7 +225,9 @@ coverage.index_ready = function ($) {
// Watch for page unload events so we can save the final sort settings:
$(window).unload(function () {
- localStorage.setItem(storage_name, sort_list.toString())
+ try {
+ localStorage.setItem(storage_name, sort_list.toString())
+ } catch(err) {}
});
};