Skip to content

Commit

Permalink
cleanDOI: Handle malformed URI escape sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Aug 14, 2024
1 parent 5b93ec8 commit 59c6e46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions test/tests/utilitiesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
});
});


Expand Down
11 changes: 8 additions & 3 deletions utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 59c6e46

Please sign in to comment.