Commit 476e0180 authored by Leo Iannacone's avatar Leo Iannacone

update ejs module to 1.0.0

parent 361aa1cc
1.0.0 / 2014-03-24
==================
* change: escape & even if it looks like an HTML entity. Don't try to prevent double-escaping.
0.8.6 / 2014-03-21
==================
* fix: Escape & even if it looks like an HTML entity. Don't try to prevent double-escaping.
0.8.5 / 2013-11-21 0.8.5 / 2013-11-21
================== ==================
...@@ -6,60 +16,60 @@ ...@@ -6,60 +16,60 @@
* fix function name changed by uglify * fix function name changed by uglify
* fixes require, closes #78 * fixes require, closes #78
0.8.4 / 2013-05-08 0.8.4 / 2013-05-08
================== ==================
* fix support for colons in filter arguments * fix support for colons in filter arguments
* fix double callback when the callback throws * fix double callback when the callback throws
* rename escape option * rename escape option
0.8.3 / 2012-09-13 0.8.3 / 2012-09-13
================== ==================
* allow pre-compiling into a standalone function [seanmonstar] * allow pre-compiling into a standalone function [seanmonstar]
0.8.2 / 2012-08-16 0.8.2 / 2012-08-16
================== ==================
* fix include "open" / "close" options. Closes #64 * fix include "open" / "close" options. Closes #64
0.8.1 / 2012-08-11 0.8.1 / 2012-08-11
================== ==================
* fix comments. Closes #62 [Nate Silva] * fix comments. Closes #62 [Nate Silva]
0.8.0 / 2012-07-25 0.8.0 / 2012-07-25
================== ==================
* add `<% include file %>` support * add `<% include file %>` support
* fix wrapping of custom require in build step. Closes #57 * fix wrapping of custom require in build step. Closes #57
0.7.3 / 2012-04-25 0.7.3 / 2012-04-25
================== ==================
* Added repository to package.json [isaacs] * Added repository to package.json [isaacs]
0.7.1 / 2012-03-26 0.7.1 / 2012-03-26
================== ==================
* Fixed exception when using express in production caused by typo. [slaskis] * Fixed exception when using express in production caused by typo. [slaskis]
0.7.0 / 2012-03-24 0.7.0 / 2012-03-24
================== ==================
* Added newline consumption support (`-%>`) [whoatemydomain] * Added newline consumption support (`-%>`) [whoatemydomain]
0.6.1 / 2011-12-09 0.6.1 / 2011-12-09
================== ==================
* Fixed `ejs.renderFile()` * Fixed `ejs.renderFile()`
0.6.0 / 2011-12-09 0.6.0 / 2011-12-09
================== ==================
* Changed: you no longer need `{ locals: {} }` * Changed: you no longer need `{ locals: {} }`
0.5.0 / 2011-11-20 0.5.0 / 2011-11-20
================== ==================
* Added express 3.x support * Added express 3.x support
...@@ -67,44 +77,44 @@ ...@@ -67,44 +77,44 @@
* Added 'json' filter * Added 'json' filter
* Fixed tests for 0.5.x * Fixed tests for 0.5.x
0.4.3 / 2011-06-20 0.4.3 / 2011-06-20
================== ==================
* Fixed stacktraces line number when used multiline js expressions [Octave] * Fixed stacktraces line number when used multiline js expressions [Octave]
0.4.2 / 2011-05-11 0.4.2 / 2011-05-11
================== ==================
* Added client side support * Added client side support
0.4.1 / 2011-04-21 0.4.1 / 2011-04-21
================== ==================
* Fixed error context * Fixed error context
0.4.0 / 2011-04-21 0.4.0 / 2011-04-21
================== ==================
* Added; ported jade's error reporting to ejs. [slaskis] * Added; ported jade's error reporting to ejs. [slaskis]
0.3.1 / 2011-02-23 0.3.1 / 2011-02-23
================== ==================
* Fixed optional `compile()` options * Fixed optional `compile()` options
0.3.0 / 2011-02-14 0.3.0 / 2011-02-14
================== ==================
* Added 'json' filter [Yuriy Bogdanov] * Added 'json' filter [Yuriy Bogdanov]
* Use exported version of parse function to allow monkey-patching [Anatoliy Chakkaev] * Use exported version of parse function to allow monkey-patching [Anatoliy Chakkaev]
0.2.1 / 2010-10-07 0.2.1 / 2010-10-07
================== ==================
* Added filter support * Added filter support
* Fixed _cache_ option. ~4x performance increase * Fixed _cache_ option. ~4x performance increase
0.2.0 / 2010-08-05 0.2.0 / 2010-08-05
================== ==================
* Added support for global tag config * Added support for global tag config
......
...@@ -144,7 +144,7 @@ function rethrow(err, str, filename, lineno){ ...@@ -144,7 +144,7 @@ function rethrow(err, str, filename, lineno){
+ lineno + '\n' + lineno + '\n'
+ context + '\n\n' + context + '\n\n'
+ err.message; + err.message;
throw err; throw err;
} }
...@@ -175,7 +175,7 @@ var parse = exports.parse = function(str, options){ ...@@ -175,7 +175,7 @@ var parse = exports.parse = function(str, options){
var stri = str[i]; var stri = str[i];
if (str.slice(i, open.length + i) == open) { if (str.slice(i, open.length + i) == open) {
i += open.length i += open.length
var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno; var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno;
switch (str[i]) { switch (str[i]) {
case '=': case '=':
...@@ -193,8 +193,13 @@ var parse = exports.parse = function(str, options){ ...@@ -193,8 +193,13 @@ var parse = exports.parse = function(str, options){
postfix = "; buf.push('"; postfix = "; buf.push('";
} }
var end = str.indexOf(close, i) var end = str.indexOf(close, i);
, js = str.substring(i, end)
if (end < 0){
throw new Error('Could not find matching close tag "' + close + '".');
}
var js = str.substring(i, end)
, start = i , start = i
, include = null , include = null
, n = 0; , n = 0;
...@@ -259,14 +264,14 @@ var parse = exports.parse = function(str, options){ ...@@ -259,14 +264,14 @@ var parse = exports.parse = function(str, options){
var compile = exports.compile = function(str, options){ var compile = exports.compile = function(str, options){
options = options || {}; options = options || {};
var escape = options.escape || utils.escape; var escape = options.escape || utils.escape;
var input = JSON.stringify(str) var input = JSON.stringify(str)
, compileDebug = options.compileDebug !== false , compileDebug = options.compileDebug !== false
, client = options.client , client = options.client
, filename = options.filename , filename = options.filename
? JSON.stringify(options.filename) ? JSON.stringify(options.filename)
: 'undefined'; : 'undefined';
if (compileDebug) { if (compileDebug) {
// Adds the fancy stack trace meta info // Adds the fancy stack trace meta info
str = [ str = [
...@@ -281,7 +286,7 @@ var compile = exports.compile = function(str, options){ ...@@ -281,7 +286,7 @@ var compile = exports.compile = function(str, options){
} else { } else {
str = exports.parse(str, options); str = exports.parse(str, options);
} }
if (options.debug) console.log(str); if (options.debug) console.log(str);
if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str; if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str;
...@@ -633,7 +638,7 @@ require.register("utils.js", function(module, exports, require){ ...@@ -633,7 +638,7 @@ require.register("utils.js", function(module, exports, require){
exports.escape = function(html){ exports.escape = function(html){
return String(html) return String(html)
.replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&amp;') .replace(/&/g, '&amp;')
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;') .replace(/>/g, '&gt;')
.replace(/'/g, '&#39;') .replace(/'/g, '&#39;')
......
ejs=function(){function require(p){if("fs"==p)return{};if("path"==p)return{};var path=require.resolve(p),mod=require.modules[path];if(!mod)throw new Error('failed to require "'+p+'"');if(!mod.exports){mod.exports={};mod.call(mod.exports,mod,mod.exports,require.relative(path))}return mod.exports}require.modules={};require.resolve=function(path){var orig=path,reg=path+".js",index=path+"/index.js";return require.modules[reg]&&reg||require.modules[index]&&index||orig};require.register=function(path,fn){require.modules[path]=fn};require.relative=function(parent){return function(p){if("."!=p.substr(0,1))return require(p);var path=parent.split("/"),segs=p.split("/");path.pop();for(var i=0;i<segs.length;i++){var seg=segs[i];if(".."==seg)path.pop();else if("."!=seg)path.push(seg)}return require(path.join("/"))}};require.register("ejs.js",function(module,exports,require){var utils=require("./utils"),path=require("path"),dirname=path.dirname,extname=path.extname,join=path.join,fs=require("fs"),read=fs.readFileSync;var filters=exports.filters=require("./filters");var cache={};exports.clearCache=function(){cache={}};function filtered(js){return js.substr(1).split("|").reduce(function(js,filter){var parts=filter.split(":"),name=parts.shift(),args=parts.join(":")||"";if(args)args=", "+args;return"filters."+name+"("+js+args+")"})}function rethrow(err,str,filename,lineno){var lines=str.split("\n"),start=Math.max(lineno-3,0),end=Math.min(lines.length,lineno+3);var context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" >> ":" ")+curr+"| "+line}).join("\n");err.path=filename;err.message=(filename||"ejs")+":"+lineno+"\n"+context+"\n\n"+err.message;throw err}var parse=exports.parse=function(str,options){var options=options||{},open=options.open||exports.open||"<%",close=options.close||exports.close||"%>",filename=options.filename,compileDebug=options.compileDebug!==false,buf="";buf+="var buf = [];";if(false!==options._with)buf+="\nwith (locals || {}) { (function(){ ";buf+="\n buf.push('";var lineno=1;var consumeEOL=false;for(var i=0,len=str.length;i<len;++i){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"=":prefix="', escape(("+line+", ";postfix=")), '";++i;break;case"-":prefix="', ("+line+", ";postfix="), '";++i;break;default:prefix="');"+line+";";postfix="; buf.push('"}var end=str.indexOf(close,i),js=str.substring(i,end),start=i,include=null,n=0;if("-"==js[js.length-1]){js=js.substring(0,js.length-2);consumeEOL=true}if(0==js.trim().indexOf("include")){var name=js.trim().slice(7).trim();if(!filename)throw new Error("filename option is required for includes");var path=resolveInclude(name,filename);include=read(path,"utf8");include=exports.parse(include,{filename:path,_with:false,open:open,close:close,compileDebug:compileDebug});buf+="' + (function(){"+include+"})() + '";js=""}while(~(n=js.indexOf("\n",n)))n++,lineno++;if(js.substr(0,1)==":")js=filtered(js);if(js){if(js.lastIndexOf("//")>js.lastIndexOf("\n"))js+="\n";buf+=prefix;buf+=js;buf+=postfix}i+=end-start+close.length-1}else if(stri=="\\"){buf+="\\\\"}else if(stri=="'"){buf+="\\'"}else if(stri=="\r"){}else if(stri=="\n"){if(consumeEOL){consumeEOL=false}else{buf+="\\n";lineno++}}else{buf+=stri}}if(false!==options._with)buf+="'); })();\n} \nreturn buf.join('');";else buf+="');\nreturn buf.join('');";return buf};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){str=["var __stack = { lineno: 1, input: "+input+", filename: "+filename+" };",rethrow.toString(),"try {",exports.parse(str,options),"} catch (err) {"," rethrow(err, __stack.input, __stack.filename, __stack.lineno);","}"].join("\n")}else{str=exports.parse(str,options)}if(options.debug)console.log(str);if(client)str="escape = escape || "+escape.toString()+";\n"+str;try{var fn=new Function("locals, filters, escape, rethrow",str)}catch(err){if("SyntaxError"==err.name){err.message+=options.filename?" in "+filename:" while compiling ejs"}throw err}if(client)return fn;return function(locals){return fn.call(this,locals,filters,escape,rethrow)}};exports.render=function(str,options){var fn,options=options||{};if(options.cache){if(options.filename){fn=cache[options.filename]||(cache[options.filename]=compile(str,options))}else{throw new Error('"cache" option requires "filename".')}}else{fn=compile(str,options)}options.__proto__=options.locals;return fn.call(options.scope,options)};exports.renderFile=function(path,options,fn){var key=path+":string";if("function"==typeof options){fn=options,options={}}options.filename=path;var str;try{str=options.cache?cache[key]||(cache[key]=read(path,"utf8")):read(path,"utf8")}catch(err){fn(err);return}fn(null,exports.render(str,options))};function resolveInclude(name,filename){var path=join(dirname(filename),name);var ext=extname(name);if(!ext)path+=".ejs";return path}exports.__express=exports.renderFile;if(require.extensions){require.extensions[".ejs"]=function(module,filename){filename=filename||module.filename;var options={filename:filename,client:true},template=fs.readFileSync(filename).toString(),fn=compile(template,options);module._compile("module.exports = "+fn.toString()+";",filename)}}else if(require.registerExtension){require.registerExtension(".ejs",function(src){return compile(src,{})})}});require.register("filters.js",function(module,exports,require){exports.first=function(obj){return obj[0]};exports.last=function(obj){return obj[obj.length-1]};exports.capitalize=function(str){str=String(str);return str[0].toUpperCase()+str.substr(1,str.length)};exports.downcase=function(str){return String(str).toLowerCase()};exports.upcase=function(str){return String(str).toUpperCase()};exports.sort=function(obj){return Object.create(obj).sort()};exports.sort_by=function(obj,prop){return Object.create(obj).sort(function(a,b){a=a[prop],b=b[prop];if(a>b)return 1;if(a<b)return-1;return 0})};exports.size=exports.length=function(obj){return obj.length};exports.plus=function(a,b){return Number(a)+Number(b)};exports.minus=function(a,b){return Number(a)-Number(b)};exports.times=function(a,b){return Number(a)*Number(b)};exports.divided_by=function(a,b){return Number(a)/Number(b)};exports.join=function(obj,str){return obj.join(str||", ")};exports.truncate=function(str,len,append){str=String(str);if(str.length>len){str=str.slice(0,len);if(append)str+=append}return str};exports.truncate_words=function(str,n){var str=String(str),words=str.split(/ +/);return words.slice(0,n).join(" ")};exports.replace=function(str,pattern,substitution){return String(str).replace(pattern,substitution||"")};exports.prepend=function(obj,val){return Array.isArray(obj)?[val].concat(obj):val+obj};exports.append=function(obj,val){return Array.isArray(obj)?obj.concat(val):obj+val};exports.map=function(arr,prop){return arr.map(function(obj){return obj[prop]})};exports.reverse=function(obj){return Array.isArray(obj)?obj.reverse():String(obj).split("").reverse().join("")};exports.get=function(obj,prop){return obj[prop]};exports.json=function(obj){return JSON.stringify(obj)}});require.register("utils.js",function(module,exports,require){exports.escape=function(html){return String(html).replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;").replace(/"/g,"&quot;")}});return require("ejs")}(); ejs=function(){function require(p){if("fs"==p)return{};if("path"==p)return{};var path=require.resolve(p),mod=require.modules[path];if(!mod)throw new Error('failed to require "'+p+'"');if(!mod.exports){mod.exports={};mod.call(mod.exports,mod,mod.exports,require.relative(path))}return mod.exports}require.modules={};require.resolve=function(path){var orig=path,reg=path+".js",index=path+"/index.js";return require.modules[reg]&&reg||require.modules[index]&&index||orig};require.register=function(path,fn){require.modules[path]=fn};require.relative=function(parent){return function(p){if("."!=p.substr(0,1))return require(p);var path=parent.split("/"),segs=p.split("/");path.pop();for(var i=0;i<segs.length;i++){var seg=segs[i];if(".."==seg)path.pop();else if("."!=seg)path.push(seg)}return require(path.join("/"))}};require.register("ejs.js",function(module,exports,require){var utils=require("./utils"),path=require("path"),dirname=path.dirname,extname=path.extname,join=path.join,fs=require("fs"),read=fs.readFileSync;var filters=exports.filters=require("./filters");var cache={};exports.clearCache=function(){cache={}};function filtered(js){return js.substr(1).split("|").reduce(function(js,filter){var parts=filter.split(":"),name=parts.shift(),args=parts.join(":")||"";if(args)args=", "+args;return"filters."+name+"("+js+args+")"})}function rethrow(err,str,filename,lineno){var lines=str.split("\n"),start=Math.max(lineno-3,0),end=Math.min(lines.length,lineno+3);var context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" >> ":" ")+curr+"| "+line}).join("\n");err.path=filename;err.message=(filename||"ejs")+":"+lineno+"\n"+context+"\n\n"+err.message;throw err}var parse=exports.parse=function(str,options){var options=options||{},open=options.open||exports.open||"<%",close=options.close||exports.close||"%>",filename=options.filename,compileDebug=options.compileDebug!==false,buf="";buf+="var buf = [];";if(false!==options._with)buf+="\nwith (locals || {}) { (function(){ ";buf+="\n buf.push('";var lineno=1;var consumeEOL=false;for(var i=0,len=str.length;i<len;++i){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"=":prefix="', escape(("+line+", ";postfix=")), '";++i;break;case"-":prefix="', ("+line+", ";postfix="), '";++i;break;default:prefix="');"+line+";";postfix="; buf.push('"}var end=str.indexOf(close,i);if(end<0){throw new Error('Could not find matching close tag "'+close+'".')}var js=str.substring(i,end),start=i,include=null,n=0;if("-"==js[js.length-1]){js=js.substring(0,js.length-2);consumeEOL=true}if(0==js.trim().indexOf("include")){var name=js.trim().slice(7).trim();if(!filename)throw new Error("filename option is required for includes");var path=resolveInclude(name,filename);include=read(path,"utf8");include=exports.parse(include,{filename:path,_with:false,open:open,close:close,compileDebug:compileDebug});buf+="' + (function(){"+include+"})() + '";js=""}while(~(n=js.indexOf("\n",n)))n++,lineno++;if(js.substr(0,1)==":")js=filtered(js);if(js){if(js.lastIndexOf("//")>js.lastIndexOf("\n"))js+="\n";buf+=prefix;buf+=js;buf+=postfix}i+=end-start+close.length-1}else if(stri=="\\"){buf+="\\\\"}else if(stri=="'"){buf+="\\'"}else if(stri=="\r"){}else if(stri=="\n"){if(consumeEOL){consumeEOL=false}else{buf+="\\n";lineno++}}else{buf+=stri}}if(false!==options._with)buf+="'); })();\n} \nreturn buf.join('');";else buf+="');\nreturn buf.join('');";return buf};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){str=["var __stack = { lineno: 1, input: "+input+", filename: "+filename+" };",rethrow.toString(),"try {",exports.parse(str,options),"} catch (err) {"," rethrow(err, __stack.input, __stack.filename, __stack.lineno);","}"].join("\n")}else{str=exports.parse(str,options)}if(options.debug)console.log(str);if(client)str="escape = escape || "+escape.toString()+";\n"+str;try{var fn=new Function("locals, filters, escape, rethrow",str)}catch(err){if("SyntaxError"==err.name){err.message+=options.filename?" in "+filename:" while compiling ejs"}throw err}if(client)return fn;return function(locals){return fn.call(this,locals,filters,escape,rethrow)}};exports.render=function(str,options){var fn,options=options||{};if(options.cache){if(options.filename){fn=cache[options.filename]||(cache[options.filename]=compile(str,options))}else{throw new Error('"cache" option requires "filename".')}}else{fn=compile(str,options)}options.__proto__=options.locals;return fn.call(options.scope,options)};exports.renderFile=function(path,options,fn){var key=path+":string";if("function"==typeof options){fn=options,options={}}options.filename=path;var str;try{str=options.cache?cache[key]||(cache[key]=read(path,"utf8")):read(path,"utf8")}catch(err){fn(err);return}fn(null,exports.render(str,options))};function resolveInclude(name,filename){var path=join(dirname(filename),name);var ext=extname(name);if(!ext)path+=".ejs";return path}exports.__express=exports.renderFile;if(require.extensions){require.extensions[".ejs"]=function(module,filename){filename=filename||module.filename;var options={filename:filename,client:true},template=fs.readFileSync(filename).toString(),fn=compile(template,options);module._compile("module.exports = "+fn.toString()+";",filename)}}else if(require.registerExtension){require.registerExtension(".ejs",function(src){return compile(src,{})})}});require.register("filters.js",function(module,exports,require){exports.first=function(obj){return obj[0]};exports.last=function(obj){return obj[obj.length-1]};exports.capitalize=function(str){str=String(str);return str[0].toUpperCase()+str.substr(1,str.length)};exports.downcase=function(str){return String(str).toLowerCase()};exports.upcase=function(str){return String(str).toUpperCase()};exports.sort=function(obj){return Object.create(obj).sort()};exports.sort_by=function(obj,prop){return Object.create(obj).sort(function(a,b){a=a[prop],b=b[prop];if(a>b)return 1;if(a<b)return-1;return 0})};exports.size=exports.length=function(obj){return obj.length};exports.plus=function(a,b){return Number(a)+Number(b)};exports.minus=function(a,b){return Number(a)-Number(b)};exports.times=function(a,b){return Number(a)*Number(b)};exports.divided_by=function(a,b){return Number(a)/Number(b)};exports.join=function(obj,str){return obj.join(str||", ")};exports.truncate=function(str,len,append){str=String(str);if(str.length>len){str=str.slice(0,len);if(append)str+=append}return str};exports.truncate_words=function(str,n){var str=String(str),words=str.split(/ +/);return words.slice(0,n).join(" ")};exports.replace=function(str,pattern,substitution){return String(str).replace(pattern,substitution||"")};exports.prepend=function(obj,val){return Array.isArray(obj)?[val].concat(obj):val+obj};exports.append=function(obj,val){return Array.isArray(obj)?obj.concat(val):obj+val};exports.map=function(arr,prop){return arr.map(function(obj){return obj[prop]})};exports.reverse=function(obj){return Array.isArray(obj)?obj.reverse():String(obj).split("").reverse().join("")};exports.get=function(obj,prop){return obj[prop]};exports.json=function(obj){return JSON.stringify(obj)}});require.register("utils.js",function(module,exports,require){exports.escape=function(html){return String(html).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;").replace(/"/g,"&quot;")}});return require("ejs")}();
\ No newline at end of file \ No newline at end of file
...@@ -92,7 +92,7 @@ function rethrow(err, str, filename, lineno){ ...@@ -92,7 +92,7 @@ function rethrow(err, str, filename, lineno){
+ lineno + '\n' + lineno + '\n'
+ context + '\n\n' + context + '\n\n'
+ err.message; + err.message;
throw err; throw err;
} }
...@@ -123,7 +123,7 @@ var parse = exports.parse = function(str, options){ ...@@ -123,7 +123,7 @@ var parse = exports.parse = function(str, options){
var stri = str[i]; var stri = str[i];
if (str.slice(i, open.length + i) == open) { if (str.slice(i, open.length + i) == open) {
i += open.length i += open.length
var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno; var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno;
switch (str[i]) { switch (str[i]) {
case '=': case '=':
...@@ -141,8 +141,13 @@ var parse = exports.parse = function(str, options){ ...@@ -141,8 +141,13 @@ var parse = exports.parse = function(str, options){
postfix = "; buf.push('"; postfix = "; buf.push('";
} }
var end = str.indexOf(close, i) var end = str.indexOf(close, i);
, js = str.substring(i, end)
if (end < 0){
throw new Error('Could not find matching close tag "' + close + '".');
}
var js = str.substring(i, end)
, start = i , start = i
, include = null , include = null
, n = 0; , n = 0;
...@@ -207,14 +212,14 @@ var parse = exports.parse = function(str, options){ ...@@ -207,14 +212,14 @@ var parse = exports.parse = function(str, options){
var compile = exports.compile = function(str, options){ var compile = exports.compile = function(str, options){
options = options || {}; options = options || {};
var escape = options.escape || utils.escape; var escape = options.escape || utils.escape;
var input = JSON.stringify(str) var input = JSON.stringify(str)
, compileDebug = options.compileDebug !== false , compileDebug = options.compileDebug !== false
, client = options.client , client = options.client
, filename = options.filename , filename = options.filename
? JSON.stringify(options.filename) ? JSON.stringify(options.filename)
: 'undefined'; : 'undefined';
if (compileDebug) { if (compileDebug) {
// Adds the fancy stack trace meta info // Adds the fancy stack trace meta info
str = [ str = [
...@@ -229,7 +234,7 @@ var compile = exports.compile = function(str, options){ ...@@ -229,7 +234,7 @@ var compile = exports.compile = function(str, options){
} else { } else {
str = exports.parse(str, options); str = exports.parse(str, options);
} }
if (options.debug) console.log(str); if (options.debug) console.log(str);
if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str; if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
exports.escape = function(html){ exports.escape = function(html){
return String(html) return String(html)
.replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&amp;') .replace(/&/g, '&amp;')
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;') .replace(/>/g, '&gt;')
.replace(/'/g, '&#39;') .replace(/'/g, '&#39;')
......
{ {
"name": "ejs", "name": "ejs",
"description": "Embedded JavaScript templates", "description": "Embedded JavaScript templates",
"version": "0.8.5", "version": "1.0.0",
"author": { "author": {
"name": "TJ Holowaychuk", "name": "TJ Holowaychuk",
"email": "tj@vision-media.ca" "email": "tj@vision-media.ca"
...@@ -28,6 +28,6 @@ ...@@ -28,6 +28,6 @@
"bugs": { "bugs": {
"url": "https://github.com/visionmedia/ejs/issues" "url": "https://github.com/visionmedia/ejs/issues"
}, },
"_id": "ejs@0.8.5", "_id": "ejs@1.0.0",
"_from": "ejs@>= 0.0.1" "_from": "ejs@>= 0.0.1"
} }
...@@ -129,22 +129,17 @@ describe('ejs.renderFile(path, options, fn)', function(){ ...@@ -129,22 +129,17 @@ describe('ejs.renderFile(path, options, fn)', function(){
}) })
describe('<%=', function(){ describe('<%=', function(){
it('should escape <script>', function(){
ejs.render('<%= name %>', { name: '<script>' }) it('should escape &amp;<script>', function(){
.should.equal('&lt;script&gt;'); ejs.render('<%= name %>', { name: '&nbsp;<script>' })
.should.equal('&amp;nbsp;&lt;script&gt;');
}) })
it("should escape '", function(){ it("should escape '", function(){
ejs.render('<%= name %>', { name: "The Jones's" }) ejs.render('<%= name %>', { name: "The Jones's" })
.should.equal('The Jones&#39;s'); .should.equal('The Jones&#39;s');
}) })
it("shouldn't escape &amp;", function(){
ejs.render('<%= name %>', { name: "Us &amp; Them" })
.should.equal('Us &amp; Them');
})
it("shouldn't escape &#93;", function(){
ejs.render('<%= name %>', { name: "The Jones&#39;s" })
.should.equal('The Jones&#39;s');
})
it("should escape &foo_bar;", function(){ it("should escape &foo_bar;", function(){
ejs.render('<%= name %>', { name: "&foo_bar;" }) ejs.render('<%= name %>', { name: "&foo_bar;" })
.should.equal('&amp;foo_bar;'); .should.equal('&amp;foo_bar;');
...@@ -156,6 +151,15 @@ describe('<%-', function(){ ...@@ -156,6 +151,15 @@ describe('<%-', function(){
ejs.render('<%- name %>', { name: '<script>' }) ejs.render('<%- name %>', { name: '<script>' })
.should.equal('<script>'); .should.equal('<script>');
}) })
it('should terminate gracefully if no close tag is found', function(){
try {
ejs.compile('<h1>oops</h1><%- name ->')
throw new Error('Expected parse failure');
} catch (err) {
err.message.should.equal('Could not find matching close tag "%>".');
}
})
}) })
describe('%>', function(){ describe('%>', function(){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment