})
})
- it('renames a file using valid names', function () {
+ it.only('renames a file using valid names', function () {
function eachPair(lst, func){
for(var i=0; i < lst.length - 1; i++){
func(lst[i], lst[i + 1])
});
});
- describe('customEncodeURI', () => {
- it('should decode', () => {
+ describe('customDecodeURI', () => {
+ it('should decode encoded URI', () => {
// given
const path = 'test%23test%2Ftest';
- const expectedResult = 'test#test/test';
+ const expectedResult = 'test#test%2Ftest';
// when
const result = customDecodeURI(path);
// then
expect(result).toEqual(expectedResult);
});
+
+ it('ignores non parsable URI and return its original form', () => {
+ // given
+ const path = 'test/path/with%wrong/sign';
+
+ // when
+ const result = customDecodeURI(path);
+
+ // then
+ expect(result).toEqual(path);
+ });
});
describe('customEncodeURI', () => {
- it('should encode', () => {
+ it('should encode URI', () => {
// given
const path = 'test#test/test';
const expectedResult = 'test%23test/test';
// then
expect(result).toEqual(expectedResult);
});
+
+ it('ignores non encodable URI and return its original form', () => {
+ // given
+ const path = 22;
+
+ // when
+ const result = customEncodeURI(path as any);
+
+ // then
+ expect(result).toEqual(path);
+ });
});
});
\ No newline at end of file
export const customEncodeURI = (path: string) => {
try {
- return encodeURIComponent(path).replace(/%2F/g, '/');
+ return path.split('/').map(encodeURIComponent).join('/');
} catch(e) {}
return path;
export const customDecodeURI = (path: string) => {
try {
- return decodeURIComponent(path.replace(/\//g, '%2F'));
+ return path.split('%2F').map(decodeURIComponent).join('%2F');
} catch(e) {}
return path;
.map(element => {
const name = getTagValue(element, 'D:displayname', '');
const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10);
- const url = customDecodeURI(getTagValue(element, 'D:href', ''));
+ const href = getTagValue(element, 'D:href', '');
+ const url = customDecodeURI(href);
const nameSuffix = name;
const collectionUuidMatch = collectionUrlPrefix.exec(url);
const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';