Permalink
Browse files

double-check, comments/cleanup

  • Loading branch information...
1 parent 8eece65 commit d8eb4604c1be9962cd7657fb8940ff7cc483cf6c @paularmstrong committed Dec 26, 2011
Showing with 12 additions and 8 deletions.
  1. +12 −8 lib/parser.js
View
20 lib/parser.js
@@ -169,6 +169,8 @@ exports.parse = function (data, tags, autoescape) {
curline = 1,
newlines = null,
lastToken,
+ rawStart = /^\{\% *raw *\%\}/,
+ rawEnd = /\{\% *endraw *\%\}$/,
inRaw = false;
for (i; i < j; i += 1) {
@@ -179,7 +181,7 @@ exports.parse = function (data, tags, autoescape) {
lines += newlines.length;
}
- if (inRaw !== false && !(/\{\%\s*endraw\s*\%\}$/).test(token)) {
+ if (inRaw !== false && !rawEnd.test(token)) {
inRaw += token;
continue;
}
@@ -192,21 +194,23 @@ exports.parse = function (data, tags, autoescape) {
} else if (variableRegexp.test(token)) {
token = exports.parseVariable(token, escape);
} else if (logicRegexp.test(token)) {
- parts = token.replace(/^\{% *| *%\}$/g, '').split(' ');
- tagname = parts.shift();
-
- if (/\{\%\s*endraw\s*\%\}$/.test(token)) {
- token = inRaw + token.replace(/\{\%\s*endraw\s*\%\}$/, '');
+ if (rawEnd.test(token)) {
+ // Don't care about the content in a raw tag, so end tag may not start correctly
+ token = inRaw + token.replace(rawEnd, '');
inRaw = false;
stack[index].push(token);
continue;
}
- if (/^\{\%\s*raw\s*\%\}/.test(token)) {
- inRaw = token.replace(/^\{\%\s*raw\s*\%\}/, '');
+ if (rawStart.test(token)) {
+ // Have to check the whole token directly, not just parts, as the tag may not end correctly while in raw
+ inRaw = token.replace(rawStart, '');
continue;
}
+ parts = token.replace(/^\{% *| *%\}$/g, '').split(' ');
+ tagname = parts.shift();
+
if (index > 0 && (/^end/).test(tagname)) {
lastToken = _.last(stack[stack.length - 2]);
if ('end' + lastToken.name === tagname) {

0 comments on commit d8eb460

Please sign in to comment.