Skip to content
Closed
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
18 changes: 18 additions & 0 deletions packages/@ember/-internals/glimmer/lib/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div>someString</div>')
```

@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
Expand Down