Skip to content

Commit

Permalink
Fix URl encode in frontend
Browse files Browse the repository at this point in the history
Decode and encode URL only when loading remote pipeline.
  • Loading branch information
skodapetr committed Dec 6, 2022
1 parent 1b23c9d commit 0c043f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
3 changes: 2 additions & 1 deletion frontend/server/routes/handlers/create-execution-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ async function securePipeline(req, requestContent) {
"value": entry["value"],
};
} else if (remote !== undefined) {
const content = await httpGetContentJsonLd(remote);
const sanitizedUrl = encodeURI(decodeURI(remote));
const content = await httpGetContentJsonLd(sanitizedUrl);
return {
"contentType": CONTENT.JSONLD,
"fileName": "pipeline.jsonld",
Expand Down
21 changes: 7 additions & 14 deletions frontend/server/routes/handlers/http-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function httpGetContent(url, accept) {
"headers": {
"accept": accept,
},
"url": sanitizeUrl(url),
"url": url,
};
return new Promise((resolve, reject) => {
request.get(options, (error, response, body) => {
Expand All @@ -31,13 +31,6 @@ async function httpGetContent(url, accept) {
});
}

/**
* Required to make it work with national characters in URL.
*/
function sanitizeUrl(url) {
return encodeURI(decodeURI(url));
}

/**
* Each part must contain: value, contentType and fileName.
*/
Expand All @@ -56,7 +49,7 @@ function httpPostContent(url, parts, headers) {
}));
}
const options = {
"url": sanitizeUrl(url),
"url": url,
"headers": headers,
"formData": formData
};
Expand All @@ -65,7 +58,7 @@ function httpPostContent(url, parts, headers) {

function httpGetForProxy(url, req, res, extra = {}) {
const options = {
"url": sanitizeUrl(url),
"url": url,
"headers": extra.headers ?? req.headers,
"qs": extra.query ?? req.query,
};
Expand All @@ -86,7 +79,7 @@ function handleConnectionError(url, error, res) {

function httpPostForProxy(url, req, res) {
const options = {
"url": sanitizeUrl(url),
"url": url,
"headers": req.headers,
"qs": req.query,
"form": req.body,
Expand All @@ -98,7 +91,7 @@ function httpPostForProxy(url, req, res) {

function httpDeleteForProxy(url, req, res, extra = {}) {
const options = {
"url": sanitizeUrl(url),
"url": url,
"headers": extra.headers ?? req.headers,
"qs": extra.query ?? req.query,
};
Expand All @@ -109,7 +102,7 @@ function httpDeleteForProxy(url, req, res, extra = {}) {

function httpPutContent(url, req, res, extra = {}) {
const options = {
"url": sanitizeUrl(url),
"url": url,
"qs": req.query,
"formData": extra?.formData,
};
Expand All @@ -120,7 +113,7 @@ function httpPutContent(url, req, res, extra = {}) {

function httpPutForProxy(url, req, res) {
const options = {
"url": sanitizeUrl(url),
"url": url,
"qs": req.query,
"form": req.body
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/server/routes/handlers/import-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async function secureContent(req, requestContent) {
"value": entry["value"],
}];
} else if (req.query["iri"] !== undefined) {
const url = req.query["iri"];
const content = await httpGetContentJsonLd(url);
const sanitizedUrl = encodeURI(decodeURI(req.query["iri"]));
const content = await httpGetContentJsonLd(sanitizedUrl);
return [{
"contentType": CONTENT.JSONLD,
"fileName": "content.jsonld",
Expand Down
8 changes: 4 additions & 4 deletions frontend/server/routes/handlers/localize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ async function handleLocalize(req, res) {
}
const url = STORAGE_API_URL + "/management/localize";
const parts = {
"options": options,
"content": content,
"options": [options],
"content": [content],
};
const headers = {
"accept": req.headers["accept"] ?? CONTENT.JSONLD,
Expand Down Expand Up @@ -81,8 +81,8 @@ async function secureContent(req, requestContent) {
"value": entry["value"],
};
} else if (req.query["iri"] !== undefined) {
const url = req.query["iri"];
const content = await httpGetContentJsonLd(url);
const sanitizedUrl = encodeURI(decodeURI(req.query["iri"]));
const content = await httpGetContentJsonLd(sanitizedUrl);
return {
"contentType": CONTENT.JSONLD,
"fileName": "content.jsonld",
Expand Down

0 comments on commit 0c043f3

Please sign in to comment.