diff --git a/test/tests/utilitiesTest.js b/test/tests/utilitiesTest.js index 60b1bc4..8569974 100644 --- a/test/tests/utilitiesTest.js +++ b/test/tests/utilitiesTest.js @@ -112,6 +112,10 @@ describe("Zotero.Utilities", function() { it("should parse a DOI in brackets", function () { assert.equal(cleanDOI(`Foo bar [${doi}] foo bar`), doi); }); + + it("should parse a DOI with an invalid URI-encoded character", function () { + assert.equal(cleanDOI('https://doi.org/10.101/%E0%A4%A')) + }); }); diff --git a/utilities.js b/utilities.js index 7c3581f..fa145dd 100644 --- a/utilities.js +++ b/utilities.js @@ -482,9 +482,14 @@ var Utilities = { if(typeof(x) != "string") { throw new Error("cleanDOI: argument must be a string"); } - // If it's a URL, decode it - if (x.match(/^https?:/)) { - x = decodeURIComponent(x); + // If it's a URL, try to decode it + if (/^https?:/.test(x)) { + try { + x = decodeURIComponent(x); + } + catch (e) { + // URI contains an invalid escape sequence - ignore + } } // Even if it's not a URL, decode %3C followed by %3E as < > var openingPos = x.indexOf("%3C");