www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 1deba232facfe8351b08f88adf755e146108bbf4
parent 56289b66932b6542a7e14d81efa333ee2f750d51
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu, 26 Oct 2017 00:54:05 -0400

Fall back to en-US sorting if we can't parse the locale

Diffstat:
Mchrome/content/zotero/xpcom/zotero.js | 32+++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -1536,7 +1536,12 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); } // Extract a valid language tag - locale = locale.match(/^[a-z]{2}(\-[A-Z]{2})?/)[0]; + try { + locale = locale.match(/^[a-z]{2}(\-[A-Z]{2})?/)[0]; + } + catch (e) { + throw new Error(`Error parsing locale ${locale}`); + } locales = [locale]; } @@ -1549,12 +1554,25 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); catch (e) { Zotero.logError(e); - // If there's an error, just skip sorting - collator = { - compare: function (a, b) { - return 0; - } - }; + // Fall back to en-US sorting + try { + Zotero.logError("Falling back to en-US sorting"); + collator = new Intl.Collator(['en-US'], { + ignorePunctuation: true, + numeric: true, + sensitivity: 'base' + }); + } + catch (e) { + Zotero.logError(e); + + // If there's still an error, just skip sorting + collator = { + compare: function (a, b) { + return 0; + } + }; + } } // Grab all ASCII punctuation and space at the begining of string