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

Backslash in template should be escaped before rendering #145

Closed
compulim opened this issue Aug 9, 2012 · 2 comments
Closed

Backslash in template should be escaped before rendering #145

compulim opened this issue Aug 9, 2012 · 2 comments

Comments

@compulim
Copy link

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 http://borismoore.github.com/jsrender/demos/step-by-step/20_without-jquery.html.

jsviews.templates('\\\\').render({})

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

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

@BorisMoore
Copy link
Owner

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

"\\".length
1
"\".length
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 added a commit that referenced this issue Dec 3, 2012
… 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
 invocation.

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
@BorisMoore
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants