Skip to content

Commit e9beb1e

Browse files
committed
fix(translation): DOMPurify does not work in non-DOM
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent b2f38e1 commit e9beb1e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/translation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function translate<T extends string>(app: string, text: T, placeholders?:
6363
* @param optionsOrNumber - The translation options or a number to replace `%n` with
6464
* @param options - Options object
6565
* @param options.escape - Enable/disable auto escape of placeholders (by default enabled)
66-
* @param options.sanitize - Enable/disable sanitization (by default enabled)
66+
* @param options.sanitize - Enable/disable sanitization (by default enabled) [WARNING: This only work in DOM environment!]
6767
*/
6868
export function translate<T extends string>(
6969
app: string,
@@ -92,7 +92,7 @@ export function translate<T extends string>(
9292
}
9393

9494
const identity = <T>(value: T): T => value
95-
const optSanitize = allOptions.sanitize ? DOMPurify.sanitize : identity
95+
const optSanitize = (allOptions.sanitize ? DOMPurify.sanitize : identity) || identity
9696
const optEscape = allOptions.escape ? escapeHTML : identity
9797

9898
const isValidReplacement = (value: unknown) => typeof value === 'string' || typeof value === 'number'

0 commit comments

Comments
 (0)