Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make escapeExpression public #18791

Closed
wants to merge 1 commit into from
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