PDA

View Full Version : [Solved] [1.1/1.0.1a] Template compile JavaScript Encoding + fix



nico
7 Aug 2007, 6:26 AM
Hello,

I got syntax errors when using the following template (notice the line break within the alert):



new Ext.Template("<a href='#' onclick='alert(\"This is \\n a line break\");>test</a>");

Problem is, that backslashes are not escaped.

Current:


body.push(this.html.replace(/(\r\n|\n)/g, '\\n').replace("'", "\\'").replace(this.re, fn));(from 1.0.1a version with the meanwhile fixed apostrophe escaping bug)


Suggested fix:

body.push(this.html.replace(/\\/g, "\\\\").replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));

Backslashes have to be the first thing too be escaped. Else other escapings are destoyed.
Dont forget the Ext.isGecko Branch ;-)

Thanks for all the great stuff,
Nico

jack.slocum
8 Aug 2007, 12:08 AM
Thanks. I've added it to the code.