From 1deba232facfe8351b08f88adf755e146108bbf4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 26 Oct 2017 00:54:05 -0400 Subject: [PATCH] Fall back to en-US sorting if we can't parse the locale --- chrome/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 index 47ca034e35..10f5a4186c 100644 --- 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