Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>
'some%22file.pdf',
'some%20file.pdf',
"G%C3%BCnter's%20file.pdf",
+ 'table%&?*2',
'bar' // make sure we can go back to the original name as a last step
];
eachPair(names, (from, to) => {
//
// SPDX-License-Identifier: AGPL-3.0
-import { customEncodeURI, encodeHash } from "./url";
+import { customEncodeURI } from "./url";
export class WebDAV {
: ''}${customEncodeURI(config.url)}`);
if (config.headers && config.headers.Destination) {
- config.headers.Destination = encodeHash(config.headers.Destination);
+ const regexp = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/;
+ const match = decodeURIComponent(config.headers.Destination).match(regexp) || {};
+ config.headers.Destination = `${match[1]}${match[2]}${customEncodeURI(match[3])}`;
}
const headers = { ...this.defaults.headers, ...config.headers };
//
// SPDX-License-Identifier: AGPL-3.0
-export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string) => {
+import { customDecodeURI } from "./url";
+
+export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string, skipDecoding: boolean = false) => {
const [el] = Array.from(document.getElementsByTagName(tagName));
const URI = el ? htmlDecode(el.innerHTML) : defaultValue;
- try {
- return decodeURI(URI);
- } catch(e) {}
+ if (!skipDecoding) {
+ try {
+ return customDecodeURI(URI);
+ } catch(e) {}
+ }
return URI;
};
// 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" }]);
});
+
+ it('should extract ecoded data and do not encode already encoded props', () => {
+ // given
+ const xmlString = '<?xml version="1.0" encoding="UTF-8"?><D:multistatus xmlns:D="DAV:"><D:response><D:href>/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/</D:href><D:propstat><D:prop><D:resourcetype><D:collection xmlns:D="DAV:"/></D:resourcetype><D:getlastmodified>Fri, 26 Mar 2021 11:45:50 GMT</D:getlastmodified><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:displayname></D:displayname></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response><D:response><D:href>/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/table%25&%3F%2A2</D:href><D:propstat><D:prop><D:resourcetype></D:resourcetype><D:getcontentlength>3</D:getcontentlength><D:getlastmodified>Fri, 26 Mar 2021 11:45:50 GMT</D:getlastmodified><D:getetag>"166fe1e1a403fb683"</D:getetag><D:getcontenttype>text/plain; charset=utf-8</D:getcontenttype><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:displayname>table%&?*2</D:displayname></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>';
+ const parser = new DOMParser();
+ const xmlDoc = parser.parseFromString(xmlString, "text/xml");
+
+ // when
+ const result = extractFilesData(xmlDoc);
+
+ // then
+ expect(result).toEqual([{ id: "zzzzz-xxxxx-vvvvvvvvvvvvvvv/table%&?*2", name: "table%&?*2", path: "", size: 3, type: "file", url: "/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/table%&?*2" }]);
+ });
});
describe('getFileFullPath', () => {
import { CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file";
import { getTagValue } from "~/common/xml";
import { getNodeChildren, Tree, mapTree } from '~/models/tree';
-import { customDecodeURI } from "~/common/url";
export const sortFilesTree = (tree: Tree<CollectionDirectory | CollectionFile>) => {
return mapTree<CollectionDirectory | CollectionFile>(node => {
.from(document.getElementsByTagName('D:response'))
.slice(1) // omit first element which is collection itself
.map(element => {
- const name = getTagValue(element, 'D:displayname', '');
- const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10);
- const href = getTagValue(element, 'D:href', '');
- const url = customDecodeURI(href);
+ const name = getTagValue(element, 'D:displayname', '', true); // skip decoding as value should be already decoded
+ const size = parseInt(getTagValue(element, 'D:getcontentlength', '0', true), 10);
+ const url = getTagValue(element, 'D:href', '');
const nameSuffix = name;
const collectionUuidMatch = collectionUrlPrefix.exec(url);
const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';