Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Render %%> as %> #46

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module.exports = Scanner = (function() {

Scanner.modePatterns = {
data: /(.*?)(<%%|<%\s*(\#)|<%(([=-])?)|\n|$)/,
data: /(.*?)(<%%|%%>|<%\s*(\#)|<%(([=-])?)|\n|$)/,
code: /(.*?)((((:|(->|=>))\s*))?%>|\n|$)/,
comment: /(.*?)(%>|\n|$)/
};
Expand Down Expand Up @@ -73,6 +73,9 @@
if (this.tail === "<%%") {
this.buffer += "<%";
return this.scan(callback);
} else if (this.tail === "%%>") {
this.buffer += "%>";
return this.scan(callback);
} else if (this.tail === "\n") {
this.buffer += this.tail;
this.lineNo++;
Expand Down
6 changes: 5 additions & 1 deletion src/scanner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module.exports = class Scanner
@modePatterns:
data: /(.*?)(<%%|<%\s*(\#)|<%(([=-])?)|\n|$)/
data: /(.*?)(<%%|%%>|<%\s*(\#)|<%(([=-])?)|\n|$)/
code: /(.*?)((((:|(->|=>))\s*))?%>|\n|$)/
comment: /(.*?)(%>|\n|$)/

Expand Down Expand Up @@ -59,6 +59,10 @@ module.exports = class Scanner
@buffer += "<%"
@scan callback

else if @tail is "%%>"
@buffer += "%>"
@scan callback

else if @tail is "\n"
@buffer += @tail
@lineNo++
Expand Down
4 changes: 4 additions & 0 deletions test/test_eco.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ module.exports =
test.same "<%", eco.render "<%%"
test.done()

"rendering an escaped %>": (test) ->
test.same "%>", eco.render "%%>"
test.done()

"requiring eco templates as modules": (test) ->
hello = require __dirname + "/fixtures/hello.eco"
test.ok typeof hello is "function"
Expand Down
7 changes: 7 additions & 0 deletions test/test_scanner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ module.exports =
test.same ["recordCode", "'<%%'"], tokens.shift()
test.done()

"%%> prints an escaped %> in data mode": (test) ->
tokens = scan "a %%> b <%= '%%'+'>' %>"
test.same ["printString", "a %> b "], tokens.shift()
test.same ["beginCode", print: true, safe: false], tokens.shift()
test.same ["recordCode", "'%%'+'>'"], tokens.shift()
test.done()

"unexpected newline in code block": (test) ->
tokens = scan "foo\nhello <% do 'thing'\n %>"
test.same ["printString", "foo\nhello "], tokens.shift()
Expand Down