Skip to content

Commit

Permalink
Backend eXist fixing the problem of saving versions with time, contai…
Browse files Browse the repository at this point in the history
…ning ':'. Closing cirsfid-unibo#8
  • Loading branch information
obujor committed Jun 11, 2018
1 parent 80a14a4 commit 01de8b7
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions documentsdb/utils/backend_exist.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ exports.deleteFile = function (path, file, callback, existConfig) {


function encode_write(str) {
return str.split('/').map(encodeURIComponent).join('/');
return str.split('/')
.map(R.compose(encodeURIComponent, encodeIllegalCharacters))
.join('/');
// return (
// str
// .replace('%', '%25')
Expand All @@ -186,17 +188,33 @@ function encode_write(str) {
// );
}

// Encode illegal characters in eXist's scheme name
// This will avoid the following exeption:
// Caused by: java.lang.IllegalArgumentException:
// Invalid URI: Illegal character in scheme name: ita@2018-06-11:00:01
// The problem is ':', the idea is to encode it twice, the first time
// in this function and the second time in encode_write using encodeURIComponent
function encodeIllegalCharacters(str) {
return str.replace(/:/g, '%3A');
}

// Same as above, repeat the decode in order to fix the double encoding of ':'
// Here we can decode all characters unlike encode it's safe
function decodeIllegalCharacters(str) {
return str.replace(encodedRegex, replaceEncoded)
}

function decode_ls(str) {
return decodeURI(
str.replace(encodedRegex, replaceEncoded)
decodeIllegalCharacters(str.replace(encodedRegex, replaceEncoded))
);
// .replace('%23', '#')
// .replace('%3A', ':')
// .replace('%25', '%');
}

function encode(str) {
return encodeURI(str);
return encode_write(str);
// Uncomment for eXist 2.2
// .replace(specialRegex, replaceSpecial)
// // .replace('#', '%23')
Expand Down Expand Up @@ -232,6 +250,7 @@ var encodedMap = R.invertObj({
"!": "%21",
"#": "%23",
"$": "%24",
"%": "%25",
"&": "%26",
"'": "%27",
"(": "%28",
Expand Down

0 comments on commit 01de8b7

Please sign in to comment.