From f5f72a4ee9b00aab5492f8991677b6503a6f2ac3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Tue, 23 Mar 2021 23:12:23 +0100 Subject: [PATCH] 17337: Added % sign handling in collection files MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- src/common/url.test.ts | 2 +- src/common/url.ts | 12 ++++++++++-- src/common/webdav.ts | 2 +- src/common/xml.ts | 8 +++++++- src/components/tree/virtual-tree.tsx | 1 - .../collection-service-files-response.ts | 7 +++++-- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/common/url.test.ts b/src/common/url.test.ts index 47530966..80181a74 100644 --- a/src/common/url.test.ts +++ b/src/common/url.test.ts @@ -48,7 +48,7 @@ describe('url', () => { it('should encode', () => { // given const path = 'test#test/test'; - const expectedResult = 'test%23test%2Ftest'; + const expectedResult = 'test%23test/test'; // when const result = customEncodeURI(path); diff --git a/src/common/url.ts b/src/common/url.ts index 0d2549c1..7a9a5158 100644 --- a/src/common/url.ts +++ b/src/common/url.ts @@ -19,11 +19,19 @@ export function normalizeURLPath(url: string) { } export const customEncodeURI = (path: string) => { - return encodeURIComponent(path.replace(/%2F/g, '/')); + try { + return encodeURIComponent(path).replace(/%2F/g, '/'); + } catch(e) {} + + return path; }; export const customDecodeURI = (path: string) => { - return decodeURIComponent(path.replace(/\//g, '%2F')); + try { + return decodeURIComponent(path.replace(/\//g, '%2F')); + } catch(e) {} + + return path; }; export const encodeHash = (path: string) => { diff --git a/src/common/webdav.ts b/src/common/webdav.ts index ca3b6d74..8d071fa6 100644 --- a/src/common/webdav.ts +++ b/src/common/webdav.ts @@ -79,7 +79,7 @@ export class WebDAV { ? this.defaults.baseURL+'/' : ''}${customEncodeURI(config.url)}`); - if (config.headers && config.headers.Destination && config.headers.Destination.indexOf('#') > -1) { + if (config.headers && config.headers.Destination) { config.headers.Destination = encodeHash(config.headers.Destination); } diff --git a/src/common/xml.ts b/src/common/xml.ts index 3c6feb5d..751a327c 100644 --- a/src/common/xml.ts +++ b/src/common/xml.ts @@ -4,7 +4,13 @@ export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string) => { const [el] = Array.from(document.getElementsByTagName(tagName)); - return decodeURI(el ? htmlDecode(el.innerHTML) : defaultValue); + const URI = el ? htmlDecode(el.innerHTML) : defaultValue; + + try { + return decodeURI(URI); + } catch(e) {} + + return URI; }; const htmlDecode = (input: string) => { diff --git a/src/components/tree/virtual-tree.tsx b/src/components/tree/virtual-tree.tsx index 54938969..4e4500b7 100644 --- a/src/components/tree/virtual-tree.tsx +++ b/src/components/tree/virtual-tree.tsx @@ -182,7 +182,6 @@ export const VirtualTree = withStyles(styles)( class Component extends React.Component & WithStyles, {}> { render(): ReactElement { const { items, render } = this.props; - return {({ height, width }) => { return VirtualList(height, width, items || [], render, this.props); diff --git a/src/services/collection-service/collection-service-files-response.ts b/src/services/collection-service/collection-service-files-response.ts index 0dd7260b..9a05fb61 100644 --- a/src/services/collection-service/collection-service-files-response.ts +++ b/src/services/collection-service/collection-service-files-response.ts @@ -34,7 +34,8 @@ export const extractFilesData = (document: Document) => { const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : ''; const directory = url .replace(collectionUrlPrefix, '') - .replace(nameSuffix, ''); + .replace(nameSuffix, '') + .replace(/\/\//g, '/'); const parentPath = directory.replace(/\/$/, ''); const data = { @@ -48,9 +49,11 @@ export const extractFilesData = (document: Document) => { path: parentPath, }; - return getTagValue(element, 'D:resourcetype', '') + const result = getTagValue(element, 'D:resourcetype', '') ? createCollectionDirectory(data) : createCollectionFile({ ...data, size }); + + return result; }); }; -- 2.30.2