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

Template stability fixes #2

Open
ghost opened this issue Jul 8, 2011 · 0 comments
Open

Template stability fixes #2

ghost opened this issue Jul 8, 2011 · 0 comments

Comments

@ghost
Copy link

ghost commented Jul 8, 2011

Hi. Thanks for the good work.

I suggest few small changes to make the generated template functions more stable:

Add newlines (\n) before "out+=", this allows the templates to contain single line comments (//), otherwise these comments are carried in the generated function code thus breaking it.

line 134:

for ( var m=0,l=arr.length; m < l; m++ )
str += arr[m].charAt(0) !== '\x1b' ?
"\nout+='" + arr[m].replace(/(|["'])/g, '$1') + "'" : (arr[m].charAt(1) === '=' ?
';\nout+=(' + arr[m].substr(2) + ');' : (arr[m].charAt(1) === '!' ?
';\nout+=$.jqotenc((' + arr[m].substr(2) + '));' : ';' + arr[m].substr(1)));

Add check for null and undefined values in jqoteenc. Without this check jqotenc crashes on null and undefined values because they don't have .toString() method. I guess booleans will crash too, but I haven't tested this.

line 168:

jqotenc: function(str) {
if(str === null || str === undefined) return '';
return str.toString()
.replace(/&(?!\w+;)/g, '&')
.split('<').join('<').split('>').join('>')
.split('"').join('"').split("'").join(''');

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

0 participants