From 355df1d02265d2937af1b101f1356d89366a7943 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 15 May 2021 10:33:43 +0200 Subject: [PATCH] Fixing url encoding issues #272 URLs that contain special characters (got media, face or directory) got parsed the wrong way, this commit fixes it. --- src/frontend/app/ui/faces/Person.ts | 2 +- src/frontend/app/ui/faces/face/face.component.ts | 13 ++++++------- src/frontend/app/ui/gallery/MediaIcon.ts | 6 +++--- .../directory/directory.gallery.component.ts | 9 ++++----- src/frontend/app/ui/gallery/gallery.service.ts | 3 ++- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/frontend/app/ui/faces/Person.ts b/src/frontend/app/ui/faces/Person.ts index 629e824c..141ae06b 100644 --- a/src/frontend/app/ui/faces/Person.ts +++ b/src/frontend/app/ui/faces/Person.ts @@ -13,6 +13,6 @@ export class Person implements PersonDTO { } public static getThumbnailUrl(that: PersonDTO): string { - return Utils.concatUrls(Config.Client.urlBase, '/api/person/', that.name, '/thumbnail'); + return Utils.concatUrls(Config.Client.urlBase, '/api/person/', encodeURIComponent(that.name), '/thumbnail'); } } diff --git a/src/frontend/app/ui/faces/face/face.component.ts b/src/frontend/app/ui/faces/face/face.component.ts index afeaf246..f889f839 100644 --- a/src/frontend/app/ui/faces/face/face.component.ts +++ b/src/frontend/app/ui/faces/face/face.component.ts @@ -18,13 +18,13 @@ export class FaceComponent implements OnInit, OnDestroy { @Input() person: PersonDTO; @Input() size: number; - thumbnail: PersonThumbnail = null; + public thumbnail: PersonThumbnail = null; public searchQueryDTOstr: string; constructor(private thumbnailService: ThumbnailManagerService, private sanitizer: DomSanitizer, private faceService: FacesService, - public authenticationService: AuthenticationService) { + public authenticationService: AuthenticationService) { } @@ -43,11 +43,10 @@ export class FaceComponent implements OnInit, OnDestroy { } getSanitizedThUrl(): SafeStyle { - return this.sanitizer.bypassSecurityTrustStyle('url(' + - encodeURI(this.thumbnail.Src) - .replace(/\(/g, '%28') - .replace(/'/g, '%27') - .replace(/\)/g, '%29') + ')'); + return this.sanitizer.bypassSecurityTrustStyle('url(' + this.thumbnail.Src + .replace(/\(/g, '%28') + .replace(/'/g, '%27') + .replace(/\)/g, '%29') + ')'); } ngOnDestroy(): void { diff --git a/src/frontend/app/ui/gallery/MediaIcon.ts b/src/frontend/app/ui/gallery/MediaIcon.ts index 9f1bfc20..de06f16b 100644 --- a/src/frontend/app/ui/gallery/MediaIcon.ts +++ b/src/frontend/app/ui/gallery/MediaIcon.ts @@ -24,12 +24,12 @@ export class MediaIcon { } getRelativePath(): string { - return Utils.concatUrls(this.media.directory.path, + return encodeURI(Utils.concatUrls(this.media.directory.path, this.media.directory.name, - this.media.name) + this.media.name)) // do not escape all urls with encodeURIComponent because that make the URL ugly and not needed // do not escape before concatUrls as that would make prevent optimizations - .replace(new RegExp('%', 'g'), '%25') // order important + // .replace(new RegExp('%', 'g'), '%25') // order important .replace(new RegExp('#', 'g'), '%23') .replace(new RegExp('\\$', 'g'), '%24'); } diff --git a/src/frontend/app/ui/gallery/directories/directory/directory.gallery.component.ts b/src/frontend/app/ui/gallery/directories/directory/directory.gallery.component.ts index 1a2fe727..352325ae 100644 --- a/src/frontend/app/ui/gallery/directories/directory/directory.gallery.component.ts +++ b/src/frontend/app/ui/gallery/directories/directory/directory.gallery.component.ts @@ -31,11 +31,10 @@ export class GalleryDirectoryComponent implements OnInit, OnDestroy { } getSanitizedThUrl(): SafeStyle { - return this.sanitizer.bypassSecurityTrustStyle('url(' + - encodeURI(this.thumbnail.Src) - .replace(/\(/g, '%28') - .replace(/'/g, '%27') - .replace(/\)/g, '%29') + ')'); + return this.sanitizer.bypassSecurityTrustStyle('url(' + this.thumbnail.Src + .replace(/\(/g, '%28') + .replace(/'/g, '%27') + .replace(/\)/g, '%29') + ')'); } // TODO: implement scroll diff --git a/src/frontend/app/ui/gallery/gallery.service.ts b/src/frontend/app/ui/gallery/gallery.service.ts index 3c21a42d..004e720f 100644 --- a/src/frontend/app/ui/gallery/gallery.service.ts +++ b/src/frontend/app/ui/gallery/gallery.service.ts @@ -94,7 +94,8 @@ export class GalleryService { } try { - const cw = await this.networkService.getJson('/gallery/content/' + directoryName, params); + const cw = await this.networkService.getJson('/gallery/content/' + + encodeURIComponent(directoryName), params); if (!cw || cw.notModified === true) {