mirror of https://github.com/abpframework/abp.git
4 changed files with 53 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||||
|
import { Pipe, PipeTransform } from '@angular/core'; |
||||
|
|
||||
|
@Pipe({ |
||||
|
name: 'htmlEncode', |
||||
|
}) |
||||
|
export class HtmlEncodePipe implements PipeTransform { |
||||
|
transform(value: string): string { |
||||
|
if (!value) { |
||||
|
return value; |
||||
|
} |
||||
|
|
||||
|
return value |
||||
|
.replace(/&/g, '&') |
||||
|
.replace(/</g, '<') |
||||
|
.replace(/>/g, '>') |
||||
|
.replace(/"/g, '"') |
||||
|
.replace(/'/g, '''); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
import { Injectable } from '@angular/core'; |
||||
|
|
||||
|
@Injectable({ |
||||
|
providedIn: 'root', |
||||
|
}) |
||||
|
export class HtmlEncodingService { |
||||
|
encode(value: string): string { |
||||
|
if (!value) { |
||||
|
return value; |
||||
|
} |
||||
|
|
||||
|
return value |
||||
|
.replace(/&/g, '&') |
||||
|
.replace(/</g, '<') |
||||
|
.replace(/>/g, '>') |
||||
|
.replace(/"/g, '"') |
||||
|
.replace(/'/g, '''); |
||||
|
} |
||||
|
|
||||
|
decode(value: string): string { |
||||
|
if (!value) { |
||||
|
return value; |
||||
|
} |
||||
|
|
||||
|
return value |
||||
|
.replace(/&/g, '&') |
||||
|
.replace(/</g, '<') |
||||
|
.replace(/>/g, '>') |
||||
|
.replace(/"/g, '"') |
||||
|
.replace(/'/g, "'"); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue