Navigation Menu

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

Fixes #153 #154

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/ejs.js
@@ -1,4 +1,3 @@

/*!
* EJS
* Copyright(c) 2012 TJ Holowaychuk <tj@vision-media.ca>
Expand Down Expand Up @@ -124,16 +123,18 @@ var parse = exports.parse = function(str, options){
if (str.slice(i, open.length + i) == open) {
i += open.length

var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno;
var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno, isOutput = false;
switch (str[i]) {
case '=':
prefix = "', escape((" + line + ', ';
postfix = ")), '";
isOutput = true;
++i;
break;
case '-':
prefix = "', (" + line + ', ';
postfix = "), '";
isOutput = true;
++i;
break;
default:
Expand All @@ -151,6 +152,14 @@ var parse = exports.parse = function(str, options){
js = js.substring(0, js.length - 2);
consumeEOL = true;
}

if (isOutput) {
var lastSemicolonIndex = js.trim().lastIndexOf(';');

if (lastSemicolonIndex > -1) {
js = js.trim().substring(0, lastSemicolonIndex);
}
}

if (0 == js.trim().indexOf('include')) {
var name = js.trim().slice(7).trim();
Expand Down
8 changes: 8 additions & 0 deletions test/ejs.js
Expand Up @@ -149,13 +149,21 @@ describe('<%=', function(){
ejs.render('<%= name %>', { name: "&foo_bar;" })
.should.equal('&amp;foo_bar;');
})
it("should remove trailing \";\"", function(){
ejs.render('<%= foo; %>', { foo: "bar"})
.should.equal('bar');
})
})

describe('<%-', function(){
it('should not escape', function(){
ejs.render('<%- name %>', { name: '<script>' })
.should.equal('<script>');
})
it("should remove trailing \";\"", function(){
ejs.render('<%- foo; %>', { foo: "bar"})
.should.equal('bar');
})
})

describe('%>', function(){
Expand Down