mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Fix issue with prepro.js where double-slashes inside block comments were filtered out (e.g. as part of URLs).
This commit is contained in:
parent
eb34e058c0
commit
8a048e8448
1 changed files with 32 additions and 36 deletions
|
@ -129,48 +129,44 @@ function stripComments(str) {
|
||||||
var singleQuote = false,
|
var singleQuote = false,
|
||||||
doubleQuote = false,
|
doubleQuote = false,
|
||||||
blockComment = false,
|
blockComment = false,
|
||||||
lineComment = false;
|
lineComment = false,
|
||||||
var removed = [];
|
preserveComment = false;
|
||||||
for (var i = 0, l = str.length; i < l; i++) {
|
for (var i = 0, l = str.length; i < l; i++) {
|
||||||
if (singleQuote) {
|
if (singleQuote) {
|
||||||
if (str[i] == "'" && str[i - 1] !== '\\')
|
if (str[i] == "'" && str[i - 1] !== '\\')
|
||||||
singleQuote = false;
|
singleQuote = false;
|
||||||
continue;
|
} else if (doubleQuote) {
|
||||||
}
|
|
||||||
if (doubleQuote) {
|
|
||||||
if (str[i] == '"' && str[i - 1] !== '\\')
|
if (str[i] == '"' && str[i - 1] !== '\\')
|
||||||
doubleQuote = false;
|
doubleQuote = false;
|
||||||
continue;
|
} else if (blockComment) {
|
||||||
}
|
// Is the block comment closing?
|
||||||
if (blockComment) {
|
|
||||||
if (str[i] == '*' && str[i + 1] == '/') {
|
if (str[i] == '*' && str[i + 1] == '/') {
|
||||||
str[i+1] = '';
|
if (!preserveComment)
|
||||||
blockComment = false;
|
str[i] = str[i + 1] = '';
|
||||||
}
|
blockComment = preserveComment = false;
|
||||||
removed.push(str[i]);
|
} else if (!preserveComment) {
|
||||||
str[i] = '';
|
str[i] = '';
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (lineComment) {
|
} else if (lineComment) {
|
||||||
|
// One-line comments end with the line-break
|
||||||
if (str[i + 1] == '\n' || str[i + 1] == '\r')
|
if (str[i + 1] == '\n' || str[i + 1] == '\r')
|
||||||
lineComment = false;
|
lineComment = false;
|
||||||
str[i] = '';
|
str[i] = '';
|
||||||
continue;
|
} else {
|
||||||
}
|
|
||||||
doubleQuote = str[i] == '"';
|
doubleQuote = str[i] == '"';
|
||||||
singleQuote = str[i] == "'";
|
singleQuote = str[i] == "'";
|
||||||
if (str[i] == '/') {
|
if (!blockComment && str[i] == '/') {
|
||||||
|
if (str[i + 1] == '*') {
|
||||||
// Do not filter out conditional comments and comments marked
|
// Do not filter out conditional comments and comments marked
|
||||||
// as protected (/*! */)
|
// as protected (/*! */)
|
||||||
if (str[i+1] == '*' && str[i+2] != '@' && str[i+2] != '!') {
|
preserveComment = str[i + 2] == '@' || str[i + 2] == '!';
|
||||||
|
if (!preserveComment)
|
||||||
str[i] = '';
|
str[i] = '';
|
||||||
blockComment = true;
|
blockComment = true;
|
||||||
continue;
|
} else if (str[i + 1] == '/') {
|
||||||
}
|
|
||||||
if (str[i+1] == '/') {
|
|
||||||
str[i] = '';
|
str[i] = '';
|
||||||
lineComment = true;
|
lineComment = true;
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue