Skip to content

Commit

Permalink
files: fix upload of files with special characters in filename
Browse files Browse the repository at this point in the history
Co-Authored-by: Valeria Granata <valeria@chaw.com>
  • Loading branch information
vgranata and vgranata committed Sep 14, 2022
1 parent cae31cb commit 841d166
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</ng-container>
<ng-template #downloadLink>
<ng-container *ngIf="showDownload && file.links.download; else noLink">
<a href="{{ file.links.download }}?download" *ngIf="showDownload && file.links.download">
<a href="{{ file.links.download }}?download">
<img src="{{ file.thumbnail }}" class="img-fluid" alt="{{ file.label }}">
</a>
</ng-container>
Expand Down
25 changes: 23 additions & 2 deletions projects/sonar/src/app/record/document/file/file.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
import { DocumentFile } from '../document.interface';

@Component({
selector: 'sonar-document-file',
templateUrl: './file.component.html'
})
export class FileComponent {
export class FileComponent implements OnInit {
// File object.
@Input()
file: DocumentFile;
Expand Down Expand Up @@ -61,6 +61,26 @@ export class FileComponent {
@Output()
previewClicked: EventEmitter<any> = new EventEmitter();

ngOnInit() {
let file = this.file;
if (file) {
// Unicode normalization form of filename in files.links.
Object.keys(file.links).forEach(function(key) {
if (['download', 'preview'].includes(key)) {
file.links[key] = file.links[key].replace(file.key, file.key.normalize('NFD'));
}
});

// Unicode normalization form of thumbnail link.
if (file.thumbnail) {
file.thumbnail = file.thumbnail.normalize('NFD');
}

this.file = file;
}
}


/**
* Scroll to target.
*
Expand All @@ -80,4 +100,5 @@ export class FileComponent {
preview(file: DocumentFile): void {
this.previewClicked.emit(file);
}

}

0 comments on commit 841d166

Please sign in to comment.