Skip to content

Commit

Permalink
cleanDOI: Handle malformed URI escape sequence (#36)
Browse files Browse the repository at this point in the history
* cleanDOI: Handle malformed URI escape sequence

* Add debug
  • Loading branch information
AbeJellinek authored Aug 14, 2024
1 parent 5b93ec8 commit f61f930
Show file tree
Hide file tree
Showing 2 changed files with 13 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
12 changes: 9 additions & 3 deletions utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,15 @@ 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
Zotero.debug("Not decoding URL-like DOI because of invalid escape sequence: " + x);
}
}
// Even if it's not a URL, decode %3C followed by %3E as < >
var openingPos = x.indexOf("%3C");
Expand Down

0 comments on commit f61f930

Please sign in to comment.