From 8a048e8448e5beabedf48bd8a1e28429a6d51b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 10 Nov 2011 18:29:50 +0100 Subject: [PATCH] Fix issue with prepro.js where double-slashes inside block comments were filtered out (e.g. as part of URLs). --- build/prepro.js | 68 +++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/build/prepro.js b/build/prepro.js index bb522da2..1ba879dd 100755 --- a/build/prepro.js +++ b/build/prepro.js @@ -129,50 +129,46 @@ function stripComments(str) { var singleQuote = false, doubleQuote = false, blockComment = false, - lineComment = false; - var removed = []; + lineComment = false, + preserveComment = false; for (var i = 0, l = str.length; i < l; i++) { if (singleQuote) { - if (str[i] == "'" && str[i-1] !== '\\') + if (str[i] == "'" && str[i - 1] !== '\\') singleQuote = false; - continue; - } - if (doubleQuote) { - if (str[i] == '"' && str[i-1] !== '\\') + } else if (doubleQuote) { + if (str[i] == '"' && str[i - 1] !== '\\') doubleQuote = false; - continue; - } - if (blockComment) { - if (str[i] == '*' && str[i+1] == '/') { - str[i+1] = ''; - blockComment = false; + } else if (blockComment) { + // Is the block comment closing? + if (str[i] == '*' && str[i + 1] == '/') { + if (!preserveComment) + str[i] = str[i + 1] = ''; + blockComment = preserveComment = false; + } else if (!preserveComment) { + str[i] = ''; } - removed.push(str[i]); - str[i] = ''; - continue; - } - if (lineComment) { - if (str[i+1] == '\n' || str[i+1] == '\r') + } else if (lineComment) { + // One-line comments end with the line-break + if (str[i + 1] == '\n' || str[i + 1] == '\r') lineComment = false; str[i] = ''; - continue; + } else { + doubleQuote = str[i] == '"'; + singleQuote = str[i] == "'"; + if (!blockComment && str[i] == '/') { + if (str[i + 1] == '*') { + // Do not filter out conditional comments and comments marked + // as protected (/*! */) + preserveComment = str[i + 2] == '@' || str[i + 2] == '!'; + if (!preserveComment) + str[i] = ''; + blockComment = true; + } else if (str[i + 1] == '/') { + str[i] = ''; + lineComment = true; + } + } } - doubleQuote = str[i] == '"'; - singleQuote = str[i] == "'"; - if (str[i] == '/') { - // Do not filter out conditional comments and comments marked - // as protected (/*! */) - if (str[i+1] == '*' && str[i+2] != '@' && str[i+2] != '!') { - str[i] = ''; - blockComment = true; - continue; - } - if (str[i+1] == '/') { - str[i] = ''; - lineComment = true; - continue; - } - } } return str.join('').slice(2, -2); }