OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#44856] replaced regex in upload response parsing
Eric Schubert024b60fbdac2
diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.jsindex 030ea66b760..dbbec2e87b8 100644--- a/frontend/.eslintrc.js+++ b/frontend/.eslintrc.js@@ -125,6 +125,9 @@ module.exports = {},],+ // Allow writing type union and type intersections without space+ "@typescript-eslint/space-infix-ops": "off",+// Allow empty interfaces for naming purposes (HAL resources)"@typescript-eslint/no-empty-interface": "off",diff --git a/frontend/src/app/shared/components/storages/services/upload-storage-files.service.ts b/frontend/src/app/shared/components/storages/services/upload-storage-files.service.tsindex dd6f4f2d994..e5cd0abbfe0 100644--- a/frontend/src/app/shared/components/storages/services/upload-storage-files.service.ts+++ b/frontend/src/app/shared/components/storages/services/upload-storage-files.service.ts@@ -72,18 +72,19 @@ export class UploadStorageFilesService {}private parseXmlResponse(xml:string):IStorageFile {+ const response = new DOMParser().parseFromString(xml, 'application/xml');const error = new Error(`Invalid response for uploaded file: ${xml}`);- const id = /<oc:fileid>(.*)<\/oc:fileid>/.exec(xml)?.pop();+ const id = response.getElementsByTagName('oc:fileid')[0].textContent;if (!id) { throw error; }- const mimeType = /<d:getcontenttype>(.*)<\/d:getcontenttype>/.exec(xml)?.pop();+ const mimeType = response.getElementsByTagName('d:getcontenttype')[0].textContent;if (!mimeType) { throw error; }- const size = /<oc:size>(.*)<\/oc:size>/.exec(xml)?.pop();+ const size = response.getElementsByTagName('oc:size')[0].textContent;if (!size) { throw error; }- const href = /<d:href>(.*)<\/d:href>/.exec(xml)?.pop();+ const href = response.getElementsByTagName('d:href')[0].textContent;const parts = href?.split('/');if (!parts || parts.length < 1) { throw error; }@@ -92,12 +93,12 @@ export class UploadStorageFilesService {const location = `/${parts.slice(parts.indexOf('webdav') + 1).join('/')}`;- const date = /<d:getlastmodified>(.*)<\/d:getlastmodified>/.exec(xml)?.pop();+ const date = response.getElementsByTagName('d:getlastmodified')[0].textContent;if (!date) { throw error; }const createdAt = this.timezoneService.parseDatetime(date).toISOString();const lastModifiedAt = createdAt;- const creator = /<oc:owner-display-name>(.*)<\/oc:owner-display-name>/.exec(xml)?.pop();+ const creator = response.getElementsByTagName('oc:owner-display-name')[0].textContent;if (!creator) { throw error; }return {@@ -114,16 +115,15 @@ export class UploadStorageFilesService {}private get propfindBody() {- return `- <?xml version="1.0"?>- <d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">- <d:prop>- <oc:fileid />- <d:getlastmodified />- <d:getcontenttype />- <oc:size />- <oc:owner-display-name />- </d:prop>- </d:propfind>`;+ return `<?xml version="1.0"?>+ <d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">+ <d:prop>+ <oc:fileid />+ <d:getlastmodified />+ <d:getcontenttype />+ <oc:size />+ <oc:owner-display-name />+ </d:prop>+ </d:propfind>`;}}diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.tsindex 8e454536eeb..01086a7fdb9 100644--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts@@ -142,7 +142,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD}private get addFileLinksHref() {- return (this.resource.$links as unknown & { addFileLink:IHalResourceLink }).addFileLink.href;+ return (this.resource.$links as unknown&{ addFileLink:IHalResourceLink }).addFileLink.href;}constructor(@@ -185,7 +185,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDthis.allowEditing$ = this.currentUserService- .hasCapabilities$('file_links/manage', (this.resource.project as unknown & { id:string }).id);+ .hasCapabilities$('file_links/manage', (this.resource.project as unknown&{ id:string }).id);document.body.addEventListener('dragover', this.onGlobalDragOver.bind(this));document.body.addEventListener('dragleave', this.afterGlobalDragEnd.bind(this));@@ -231,7 +231,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDthis.openSelectLocationDialog(fileList);}- private openSelectLocationDialog(files:FileList | null):void {+ private openSelectLocationDialog(files:FileList|null):void {const locals = {storageType: this.storage._links.type.href,storageTypeName: this.storageType,@@ -284,7 +284,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD}private uploadResourceLink(fileName:string, location:string):IPrepareUploadLink {- const project = (this.resource.project as unknown & { id:string }).id;+ const project = (this.resource.project as unknown&{ id:string }).id;const link = this.storage._links.prepareUpload.filter((value) => project === value.payload.projectId.toString());if (link.length === 0) {throw new Error('Cannot upload to this storage. Missing permissions in project.');@@ -369,7 +369,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD}private get fileLinkSelfLink():string {- const fileLinks = this.resource.fileLinks as unknown & { href:string };+ const fileLinks = this.resource.fileLinks as unknown&{ href:string };return `${fileLinks.href}?filters=[{"storage":{"operator":"=","values":["${this.storage.id}"]}}]`;}