From be9031fd41dfd96a9e34effe2b9ec3bb034acb62 Mon Sep 17 00:00:00 2001 From: sandstrom Date: Mon, 2 Mar 2020 13:28:14 +0100 Subject: [PATCH] Make escapeExpression public --- .../-internals/glimmer/lib/utils/string.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/@ember/-internals/glimmer/lib/utils/string.ts b/packages/@ember/-internals/glimmer/lib/utils/string.ts index 586a5daa373..29d2f0ff305 100644 --- a/packages/@ember/-internals/glimmer/lib/utils/string.ts +++ b/packages/@ember/-internals/glimmer/lib/utils/string.ts @@ -35,6 +35,24 @@ function escapeChar(chr: keyof typeof escape) { return escape[chr]; } +/** + Escapes the passed string, making it safe for use in templates. + + Replaces &, <, >, ", ', `, = in the string with the HTML-entity equivalents. + SafeString values created with `htmlSafe` are left untouched. + + ```javascript + import { escapeExpression } from '@ember/template'; + + escapeExpression('
someString
') + ``` + + @method escapeExpression + @for @ember/template + @static + @return {String} An escaped string, safe for use in templates. + @public +*/ export function escapeExpression(string: any): string { if (typeof string !== 'string') { // don't escape SafeStrings, since they're already safe