mirror of
https://github.com/zotero/zotero.git
synced 2026-10-08 03:08:19 +00:00
Local API: Decode + as a space in form-encoded requests
Some checks failed
CI / Detect changes (push) Has been cancelled
CI / Build, Upload (push) Has been cancelled
CI / Utilities Tests (push) Has been cancelled
CI / Test () (push) Has been cancelled
CI / Test (macOS NFS) (push) Has been cancelled
CI / Test (Windows arm64) (push) Has been cancelled
CI / Test (Windows x64) (push) Has been cancelled
Some checks failed
CI / Detect changes (push) Has been cancelled
CI / Build, Upload (push) Has been cancelled
CI / Utilities Tests (push) Has been cancelled
CI / Test () (push) Has been cancelled
CI / Test (macOS NFS) (push) Has been cancelled
CI / Test (Windows arm64) (push) Has been cancelled
CI / Test (Windows x64) (push) Has been cancelled
File uploads that encoded spaces as + were stored with literal + characters in the filename. https://forums.zotero.org/discussion/134038/
This commit is contained in:
parent
fb4bed7522
commit
9cbba8c4d2
2 changed files with 35 additions and 1 deletions
|
|
@ -109,7 +109,9 @@ Zotero.Server = new function () {
|
|||
var decodedData = {};
|
||||
for (let variable of splitData) {
|
||||
var splitIndex = variable.indexOf("=");
|
||||
decodedData[decodeURIComponent(variable.substr(0, splitIndex))] = decodeURIComponent(variable.substr(splitIndex+1));
|
||||
let key = variable.substr(0, splitIndex).replaceAll('+', ' ');
|
||||
let value = variable.substr(splitIndex + 1).replaceAll('+', ' ');
|
||||
decodedData[decodeURIComponent(key)] = decodeURIComponent(value);
|
||||
}
|
||||
return decodedData;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,6 +141,38 @@ describe("Zotero.Server", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("application/x-www-form-urlencoded", function () {
|
||||
it("should decode + as a space", async function () {
|
||||
var data;
|
||||
|
||||
var endpoint = "/test/" + Zotero.Utilities.randomString();
|
||||
var handler = function () {};
|
||||
handler.prototype = {
|
||||
supportedMethods: ["POST"],
|
||||
supportedDataTypes: ["application/x-www-form-urlencoded"],
|
||||
|
||||
init: function (options) {
|
||||
data = options.data;
|
||||
return 204;
|
||||
}
|
||||
};
|
||||
Zotero.Server.Endpoints[endpoint] = handler;
|
||||
|
||||
await Zotero.HTTP.request(
|
||||
"POST",
|
||||
serverPath + endpoint,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: "file+name=a+b%2Bc%20d.pdf"
|
||||
}
|
||||
);
|
||||
|
||||
assert.deepEqual(data, { "file name": "a b+c d.pdf" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("multipart/form-data", function () {
|
||||
it("should support text", async function () {
|
||||
var called = false;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue