Or just use tagged template strings to do the sanitization.


On Dec 16, 2014, at 11:37, Andrea Giammarchi 
<[email protected]<mailto:[email protected]>> wrote:

Apologies for the probably futile extra precaution but, since someone might be 
confused already, I think it must be said that nobody should ever use ES6 
interpolated strings like the following:

```js
dom.innerHTML = `<div class="${className}"></div>`;
```

unless eventual bound references are not made safe elsewhere.

In a raw template like logic, like the suggested gist, it should also, 
eventually, be like the following:

```js
dom.innerHTML = '<div class="${className}"></div>'.template({
  className: safeForHTML(className)
});
```

Still in templates, when double curly braces are in place usually means such 
safe HTML/sanitize operation is done automagically behind the scene avoiding 
repeated `safeForHTML` calls.

I hope the distinction is cleaner now.

Best Regards






On Tue, Dec 16, 2014 at 3:26 PM, Domenic Denicola 
<[email protected]<mailto:[email protected]>> wrote:
You want templates, which is something provided by many libraries (Handlebars, 
etc.). The language provides template strings as a syntactic feature.

Templates and template strings are very different. Don't be fooled by the name 
into thinking that templates are some sort of natural feature addition to 
template strings; they're in fact a different concept altogether.

From: es-discuss 
[mailto:[email protected]<mailto:[email protected]>] 
On Behalf Of Niloy Mondal
Sent: Tuesday, December 16, 2014 06:48
To: Andrea Giammarchi
Cc: [email protected]<mailto:[email protected]>
Subject: Re: how to delay interpolation of template strings?

Can this be considered for a feature request? Provision in the language to 
dynamically construct template strings and interpolate them.

On Tue, Dec 16, 2014 at 4:48 PM, Andrea Giammarchi 
<[email protected]<mailto:[email protected]>> wrote:
irony ... I think you would need to evaluate the template string inline in 
order to interpolate its result ...

OR

you just go for this method which also works down to ES3 engine:
https://gist.github.com/WebReflection/8f227532143e63649804

Regards

On Tue, Dec 16, 2014 at 10:01 AM, Niloy Mondal 
<[email protected]<mailto:[email protected]>> wrote:
Thanks, this would work.

How can I construct a template string dynamically? Like reading the template 
from a file/database and then interpolate it.

On Tue, Dec 16, 2014 at 2:29 PM, Claude Pache 
<[email protected]<mailto:[email protected]>> wrote:

Le 16 d?c. 2014 ? 09:27, Niloy Mondal 
<[email protected]<mailto:[email protected]>> a ?crit :

I want to define a template string using backquotes in a different file and 
then have it interpolated with actual values in a different file. How can I do 
it?


Just enclose it in a function:

```javascript
   function foo(a) {
        return `some template ${a}`
    }

    foo("bar") // will evaluate `some template ${"bar"}`
```

-Claude

_______________________________________________
es-discuss mailing list
[email protected]<mailto:[email protected]>
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to