From eadb2e4a0005b89cb2ca1977bb6f53652e911249 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Thu, 25 Feb 2021 21:34:41 +0100 Subject: [PATCH] 17337: Added more tests, fixed whitespace issue MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- cypress/integration/collection.spec.js | 8 ++++++- src/common/url.ts | 11 ++++++++++ src/common/webdav.ts | 4 +++- .../collection-service-files-response.test.ts | 22 ++++++++++++++++--- .../collection-service-files-response.ts | 3 ++- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/cypress/integration/collection.spec.js b/cypress/integration/collection.spec.js index 8f614591..6ac65497 100644 --- a/cypress/integration/collection.spec.js +++ b/cypress/integration/collection.spec.js @@ -138,7 +138,7 @@ describe('Collection panel tests', function () { } }); cy.get('[data-cy=collection-files-panel]') - .contains(fileName).rightclick(); + .contains(fileName).rightclick({ force: true }); cy.get('[data-cy=context-menu]') .should('contain', 'Download') .and('contain', 'Open in new tab') @@ -370,6 +370,12 @@ describe('Collection panel tests', function () { cy.get('[data-cy=context-menu]').contains('Remove selected').click(); cy.get('[data-cy=confirmation-dialog-ok-btn]').click(); cy.get('[data-cy=collection-files-panel]').contains('#foo').should('not.exist'); + + cy.get('[data-cy=collection-files-panel]').contains('bar').rightclick(); + cy.get('[data-cy=context-menu]').contains('Rename').click(); + cy.get('input[name=path]').type('bar 123 321 bar'); + cy.get('[data-cy=form-submit-btn]').click(); + cy.get('[data-cy=collection-files-panel]').contains('barbar 123 321 bar').should('exist'); }); }); diff --git a/src/common/url.ts b/src/common/url.ts index 9789b65e..6223485e 100644 --- a/src/common/url.ts +++ b/src/common/url.ts @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + export function getUrlParameter(search: string, name: string) { const safeName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)'); @@ -13,3 +17,10 @@ export function normalizeURLPath(url: string) { } return u.toString(); } + +export const escapeHashIfRequired = (name: string, defaultTransformation?: Function) => + name.indexOf('#') > -1 ? + encodeURIComponent(name) : + defaultTransformation ? + defaultTransformation(name) : + name; \ No newline at end of file diff --git a/src/common/webdav.ts b/src/common/webdav.ts index e896a207..54601f16 100644 --- a/src/common/webdav.ts +++ b/src/common/webdav.ts @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0 +import { escapeHashIfRequired } from "./url"; + export class WebDAV { defaults: WebDAVDefaults = { @@ -75,7 +77,7 @@ export class WebDAV { r.open(config.method, `${this.defaults.baseURL ? this.defaults.baseURL+'/' - : ''}${encodeURIComponent(config.url)}`); + : ''}${escapeHashIfRequired(config.url, encodeURI)}`); const headers = { ...this.defaults.headers, ...config.headers }; Object .keys(headers) diff --git a/src/services/collection-service/collection-service-files-response.test.ts b/src/services/collection-service/collection-service-files-response.test.ts index 06c8662b..ad75f572 100644 --- a/src/services/collection-service/collection-service-files-response.test.ts +++ b/src/services/collection-service/collection-service-files-response.test.ts @@ -3,16 +3,32 @@ // SPDX-License-Identifier: AGPL-3.0 import { CollectionFile } from '~/models/collection-file'; -import { getFileFullPath } from './collection-service-files-response'; +import { getFileFullPath, extractFilesData } from './collection-service-files-response'; describe('collection-service-files-response', () => { + + describe('extractFilesData', () => { + it('should extract', () => { + // given + const xmlString = '/c=xxxxx-zzzzz-vvvvvvvvvvvvvvv/Wed, 24 Feb 2021 22:16:19 GMTHTTP/1.1 200 OK/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/21582976"1666cee048aa7f98182780"2Wed, 24 Feb 2021 22:16:19 GMTtext/plain; charset=utf-8HTTP/1.1 200 OK/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/table%201%202%203133352"1666cee048aa7f98208e8"table 1 2 3Wed, 24 Feb 2021 22:16:19 GMTtext/plain; charset=utf-8HTTP/1.1 200 OK'; + const parser = new DOMParser(); + const xmlDoc = parser.parseFromString(xmlString, "text/xml"); + + // when + const result = extractFilesData(xmlDoc); + + // then + expect(result).toEqual([{ id: "zzzzz-xxxxx-vvvvvvvvvvvvvvv/2", name: "2", path: "", size: 1582976, type: "file", url: "/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/2" }, { id: "zzzzz-xxxxx-vvvvvvvvvvvvvvv/table 1 2 3", name: "table 1 2 3", path: "", size: 133352, type: "file", url: "/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/table 1 2 3" }]); + }); + }); + describe('getFileFullPath', () => { it('should encode weird names', async () => { // given - const file = { + const file = { name: '#test', path: 'http://localhost', - } as CollectionFile; + } as CollectionFile; // when const result = getFileFullPath(file); diff --git a/src/services/collection-service/collection-service-files-response.ts b/src/services/collection-service/collection-service-files-response.ts index c1176cd5..6f8b3de3 100644 --- a/src/services/collection-service/collection-service-files-response.ts +++ b/src/services/collection-service/collection-service-files-response.ts @@ -5,6 +5,7 @@ import { CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file"; import { getTagValue } from "~/common/xml"; import { getNodeChildren, Tree, mapTree } from '~/models/tree'; +import { escapeHashIfRequired } from "~/common/url"; export const sortFilesTree = (tree: Tree) => { return mapTree(node => { @@ -28,7 +29,7 @@ export const extractFilesData = (document: Document) => { const name = getTagValue(element, 'D:displayname', ''); const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10); const url = getTagValue(element, 'D:href', ''); - const nameSuffix = `/${encodeURIComponent(name) || ''}`; + const nameSuffix = `/${escapeHashIfRequired(name) || ''}`; const collectionUuidMatch = collectionUrlPrefix.exec(url); const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : ''; const directory = url -- 2.30.2