When I post the following to node (simplified example):
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:3000/action");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify({path:encodeURIComponent("E:\foo\bar.baz")}));
node.js code:
app.post('/action', function (request, response) {
var file = request.body['path'];
console.log(file);
console.log(decodeURIComponent(file));
});
I get the following output:
E%3A%0Coo%08ar.baz
E:♀oar.baz
How do I correctly decode this?
You are encoding special characters in your path as the backslash is reserved for escaping:
\f Form feed
\b Backspace
When encoded these become:
%0C
%08
From MDN:
To include a literal backslash inside a string, you must escape the backslash character
"E:\\foo\\bar.baz"