Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not bind content as innerHTML by default #126

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ import { AsyncPipe, NgTemplateOutlet } from '@angular/common';
}

@if (!column.cellTemplate) {
<span [title]="sanitizedValue" [innerHTML]="value"> </span>
@if (column.bindAsUnsafeHtml) {
<span [title]="sanitizedValue" [innerHTML]="value"> </span>
} @else {
<span [title]="sanitizedValue">{{ value }}</span>
}
} @else {
<ng-template
#cellTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class DataTableColumnDirective<TRow> implements TableColumn, OnChanges {
private columnChangesService = inject(ColumnChangesService);
@Input() name: string;
@Input() prop: TableColumnProp;
@Input({ transform: booleanAttribute }) bindAsUnsafeHtml?: boolean;
@Input({ transform: booleanAttribute }) frozenLeft: boolean;
@Input({ transform: booleanAttribute }) frozenRight: boolean;
@Input({ transform: numberAttribute }) flexGrow: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import { NgTemplateOutlet } from '@angular/common';
</ng-template>
} @else {
<span class="datatable-header-cell-wrapper">
<span class="datatable-header-cell-label draggable" (click)="onSort()" [innerHTML]="name">
<span class="datatable-header-cell-label draggable" (click)="onSort()">
{{ name }}
</span>
</span>
}
Expand Down
8 changes: 8 additions & 0 deletions projects/ngx-datatable/src/lib/types/table-column.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export interface TableColumn<TRow = any> {
*/
prop?: TableColumnProp;

/**
* By default, the property is bound using normal data binding `<span>{{content}}</span>`.
* If this property is set to true, the property will be bound as `<span [innerHTML]="content" />`.
*
* **DANGER** If enabling this feature, make sure the source of the data is trusted. This can be a vector for HTML injection attacks.
*/
bindAsUnsafeHtml?: boolean;

/**
* Cell template ref
*/
Expand Down