Local API: Decode + as a space in form-encoded requests
Some checks failed
CI / Detect changes (push) Has been cancelled
CI / Utilities Tests (push) Has been cancelled
CI / Build, Upload (push) Has been cancelled
CI / Test () (push) Has been cancelled
CI / Test (macOS NFS) (push) Has been cancelled

File uploads that encoded spaces as + were stored with literal +
characters in the filename.

https://forums.zotero.org/discussion/134038/

(cherry picked from commit 9cbba8c4d2)
This commit is contained in:
Dan Stillman 2026-10-06 11:29:06 -04:00
parent 4d4c2c1412
commit 536244c277
2 changed files with 35 additions and 1 deletions

View file

@ -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;
}

View file

@ -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;