mirror of
https://github.com/zotero/zotero.git
synced 2026-10-10 03:28:10 +00:00
Fix handling of redirecting OpenURL base URLs with url query parameter
For a URL like `https://ezproxy.school.edu/login?url=http://resolver.ebscohost.com/openurl`, without a trailing `?`, we were just adding a `%` to the end, making the URL invalid after the redirection (`/openurl&url_ver=Z39.88-2004` instead of `/openurl?url_ver=Z39.88-2004`). (And apparently no one who sent in these URLs actually tested them in-app?)
This commit is contained in:
parent
244d182293
commit
20e28d3f9e
2 changed files with 50 additions and 3 deletions
|
|
@ -3039,9 +3039,18 @@ Zotero.Utilities.Internal.OpenURL = {
|
|||
);
|
||||
if (co) {
|
||||
let base = Zotero.Prefs.get("openURL.resolver");
|
||||
// Add & if there's already a ?
|
||||
let splice = base.indexOf("?") == -1 ? "?" : "&";
|
||||
return base + splice + co;
|
||||
if (!base.endsWith('?')) {
|
||||
if (base.includes('login?url=')) {
|
||||
base += '?';
|
||||
}
|
||||
else if (base.includes('?')) {
|
||||
base += '&';
|
||||
}
|
||||
else {
|
||||
base += '?';
|
||||
}
|
||||
}
|
||||
return base + co;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -738,4 +738,42 @@ describe("Zotero.Utilities.Internal", function () {
|
|||
assert.equal(html, 'yes1yes2 yes3');
|
||||
});
|
||||
});
|
||||
|
||||
describe("OpenURL", function () {
|
||||
var item;
|
||||
|
||||
before(async function () {
|
||||
item = await createDataObject('item', { title: 'Foo Bar', date: '2024-12-19' });
|
||||
})
|
||||
|
||||
after(function () {
|
||||
Zotero.Prefs.clear('openURL.resolver');
|
||||
});
|
||||
|
||||
describe("#resolve()", function () {
|
||||
it("should add trailing '?' if no query string", async function () {
|
||||
Zotero.Prefs.set("openURL.resolver", "https://resolver.ebsco.com/c/abcdef/result");
|
||||
var url = Zotero.Utilities.Internal.OpenURL.resolve(item);
|
||||
assert.include(url, 'result?url_ver=Z39.88-2004');
|
||||
});
|
||||
|
||||
it("should add trailing '&' if already a query string", async function () {
|
||||
Zotero.Prefs.set("openURL.resolver", "https://resolver.ebscohost.com/openurl?custid=abcdef&groupid=main&profile=ftf&authtype=ip,uid");
|
||||
var url = Zotero.Utilities.Internal.OpenURL.resolve(item);
|
||||
assert.include(url, 'authtype=ip,uid&url_ver=Z39.88-2004');
|
||||
});
|
||||
|
||||
it("should add trailing '?' after /login?url=", async function () {
|
||||
Zotero.Prefs.set("openURL.resolver", "https://proxy.school.edu/login?url=https://resolver.ebscohost.com/openurl");
|
||||
var url = Zotero.Utilities.Internal.OpenURL.resolve(item);
|
||||
assert.include(url, 'openurl?url_ver=Z39.88-2004');
|
||||
});
|
||||
|
||||
it("shouldn't add trailing '?' after /login?url= if URL already ends in '?'", async function () {
|
||||
Zotero.Prefs.set("openURL.resolver", "https://proxy.school.edu/login?url=https://resolver.ebscohost.com/openurl?");
|
||||
var url = Zotero.Utilities.Internal.OpenURL.resolve(item);
|
||||
assert.include(url, 'openurl?url_ver=Z39.88-2004');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue