Backslash in template should be escaped before rendering #145

compulim opened this Issue Aug 9, 2012 · 2 comments


None yet

2 participants

compulim commented Aug 9, 2012

Rendering templates with backslash will turns two backslashes into one.

You can test the following code at a console on page


Expected: two backslashes, i.e. '\'
Actual: one backslahes, i.e. ''

p.s. template of '\t' should render '\t', instead of ' '.


Since that is JavaScript code, and you are passing a javascript string, the following string "\\" contains only one character.
Try this:

Unterminated string constant

So JsRender implementation code will see "\t" as a string with a tab character, and "\\" as a string with a single backslash.

Putting \ characters into a script block or an HTML document used as a template declaration, on the other hand, should lead to those characters being escaped so they are preserved in the rendered output. That is not being done correctly and is a bug. (Thanks for drawing my attention to this, even if it is a bit different to your specific issue!) A fix is on the way for this.

@BorisMoore BorisMoore added a commit that referenced this issue Dec 3, 2012
@BorisMoore Commit counter 22. Major update, including some BREAKING CHANGES, and…
… many

new features. More samples and documentation for new features will be added
incrementally in coming updates.

Among the changes:

Detailed APIs modified for consistent arguments and use of this
pointer, and for maximum extensibility. See updated samples for usage...

Compiled templates restructured for easier debugging.

View object restructured for clarity.

View now has a type property, e.g. type="item"
Only "item" views have index properties, but to get the index from a nested
view use view.get("item").index.

nodes collection on a view is now a function, view.nodes().

Settings grouped onto a $.views.settings object.
View navigation features improved, with view.get(...) and $.view(elem, ...)
tagCtx object provides improved access to the args and properties of a tag

Adding resources (helpers, converters, tags, etc) to a template now supported
by passing parent template to API. e.g. $.tags({...}, parentTemplate).
Many improvements to custom tags, - used also as part of JsViews integration
for new JsViews Tag Controls. (Instantiation of tags as control instances).

Template inclusion now supported with simpler syntax {{for tmpl=.../))

Fixes for issues #169, #162, #157, #156, #155, #153, #145

This has been fixed in commit 22. Please reopen if the fix does not work for you. Thanks!

@BorisMoore BorisMoore closed this Dec 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment