diff --git a/lib/ejs.js b/lib/ejs.js index f36944fb..0b58d985 100644 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -92,7 +92,7 @@ function rethrow(err, str, filename, lineno){ + lineno + '\n' + context + '\n\n' + err.message; - + throw err; } @@ -123,7 +123,7 @@ var parse = exports.parse = function(str, options){ var stri = str[i]; if (str.slice(i, open.length + i) == open) { i += open.length - + var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno; switch (str[i]) { case '=': @@ -141,8 +141,13 @@ var parse = exports.parse = function(str, options){ postfix = "; buf.push('"; } - var end = str.indexOf(close, i) - , js = str.substring(i, end) + var end = str.indexOf(close, i); + + if (end < 0){ + end = str.length; + } + + var js = str.substring(i, end) , start = i , include = null , n = 0; @@ -207,14 +212,14 @@ var parse = exports.parse = function(str, options){ var compile = exports.compile = function(str, options){ options = options || {}; var escape = options.escape || utils.escape; - + var input = JSON.stringify(str) , compileDebug = options.compileDebug !== false , client = options.client , filename = options.filename ? JSON.stringify(options.filename) : 'undefined'; - + if (compileDebug) { // Adds the fancy stack trace meta info str = [ @@ -229,7 +234,7 @@ var compile = exports.compile = function(str, options){ } else { str = exports.parse(str, options); } - + if (options.debug) console.log(str); if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str;