2019-01-27 16:12:17 +01:00
|
|
|
// This utility is based on https://github.com/zertosh/htmlescape
|
|
|
|
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
|
|
|
|
2019-05-29 13:57:26 +02:00
|
|
|
const ESCAPE_LOOKUP: { [match: string]: string } = {
|
2019-01-27 16:12:17 +01:00
|
|
|
'&': '\\u0026',
|
|
|
|
'>': '\\u003e',
|
|
|
|
'<': '\\u003c',
|
|
|
|
'\u2028': '\\u2028',
|
|
|
|
'\u2029': '\\u2029',
|
|
|
|
}
|
|
|
|
|
|
|
|
const ESCAPE_REGEX = /[&><\u2028\u2029]/g
|
|
|
|
|
2020-05-18 19:31:06 +02:00
|
|
|
export function htmlEscapeJsonString(str: string): string {
|
2020-05-18 21:24:37 +02:00
|
|
|
return str.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match])
|
2019-01-27 16:12:17 +01:00
|
|
|
}
|