Skip to content

Commit b1faf11

Browse files
Mattia VianelliMattia Vianelli
authored andcommitted
DSC-2212 Updated rendering for the item-list-preview.component.ts to use a pipe for the html escaping
1 parent 4951f8e commit b1faf11

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ds-badges *ngIf="showLabel" [object]="item" [context]="badgeContext" [showAccessStatus]="true"></ds-badges>
1010
</div>
1111
<ds-truncatable [id]="item.id">
12-
<h2 [innerHTML]="dsoTitle" [ngClass]="{'lead': true,'text-muted': !item.firstMetadataValue('dc.title')}"></h2>
12+
<h2 [innerHTML]="dsoTitle | dsEscapeHtml" [ngClass]="{'lead': true,'text-muted': !item.firstMetadataValue('dc.title')}"></h2>
1313
<ds-in-workflow-statistics *ngIf="showWorkflowStatistics" [item]="item" ></ds-in-workflow-statistics>
1414
<div>
1515
<span class="text-muted">

src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { TruncatableComponent } from '../../../truncatable/truncatable.component
3636
import { TruncatableService } from '../../../truncatable/truncatable.service';
3737
import { TruncatablePartComponent } from '../../../truncatable/truncatable-part/truncatable-part.component';
3838
import { AdditionalMetadataComponent } from '../../search-result-list-element/additional-metadata/additional-metadata.component';
39+
import {EscapeHtmlPipe} from "../../../utils/escape-html.pipe";
3940

4041
/**
4142
* This component show metadata for the given item object in the list view.
@@ -62,6 +63,7 @@ import { AdditionalMetadataComponent } from '../../search-result-list-element/ad
6263
AdditionalMetadataComponent,
6364
ItemCorrectionComponent,
6465
InWorkflowStatisticsComponent,
66+
EscapeHtmlPipe,
6567
],
6668
})
6769
export class ItemListPreviewComponent implements OnInit {

src/app/shared/utils/escape-html.pipe.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,10 @@ import {
1010
export class EscapeHtmlPipe implements PipeTransform {
1111
/**
1212
* Escape HTML special characters and convert newlines to <br>
13-
* @param value - The string to escape
14-
* @returns The escaped string safe for innerHTML rendering
13+
* @param text
1514
*/
16-
transform(value: string): string {
17-
if (!value) {
18-
return value;
19-
}
15+
transform(text: string): string {
2016
const newlineRegex = /\n/g;
21-
return value
22-
.replace(/>/g, '&gt;')
23-
.replace(/</g, '&lt;')
24-
.replace(newlineRegex, '<br>');
17+
return text.replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(newlineRegex, '<br>');
2518
}
2619
}

src/themes/custom/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { AdditionalMetadataComponent } from '../../../../../../../app/shared/obj
1919
import { TruncatableComponent } from '../../../../../../../app/shared/truncatable/truncatable.component';
2020
import { TruncatablePartComponent } from '../../../../../../../app/shared/truncatable/truncatable-part/truncatable-part.component';
2121
import { ThemedThumbnailComponent } from '../../../../../../../app/thumbnail/themed-thumbnail.component';
22+
import {EscapeHtmlPipe} from "../../../../../../../app/shared/utils/escape-html.pipe";
2223

2324
@Component({
2425
selector: 'ds-themed-item-list-preview',
@@ -44,6 +45,7 @@ import { ThemedThumbnailComponent } from '../../../../../../../app/thumbnail/the
4445
AdditionalMetadataComponent,
4546
ItemCorrectionComponent,
4647
InWorkflowStatisticsComponent,
48+
EscapeHtmlPipe,
4749
],
4850
})
4951
export class ItemListPreviewComponent extends BaseComponent {

0 commit comments

Comments
 (0)