Do not allow newlines in regex
This commit is contained in:
committed by
Richard van Velzen
parent
09d5707a8a
commit
00ad57e393
@@ -490,6 +490,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
break;
|
break;
|
||||||
} else if (ch == "\\") {
|
} else if (ch == "\\") {
|
||||||
prev_backslash = true;
|
prev_backslash = true;
|
||||||
|
} else if ("\r\n\u2028\u2029".indexOf(ch) >= 0) {
|
||||||
|
parse_error("Unexpected line terminator");
|
||||||
} else {
|
} else {
|
||||||
regexp += ch;
|
regexp += ch;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,27 @@ describe("line-endings", function() {
|
|||||||
var result = Uglify.minify(js, options);
|
var result = Uglify.minify(js, options);
|
||||||
assert.strictEqual(result.code, expected_code);
|
assert.strictEqual(result.code, expected_code);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should not allow line terminators in regexp", function() {
|
||||||
|
var inputs = [
|
||||||
|
"/\n/",
|
||||||
|
"/\r/",
|
||||||
|
"/\u2028/",
|
||||||
|
"/\u2029/",
|
||||||
|
"/someRandomTextLike[]()*AndThen\n/"
|
||||||
|
]
|
||||||
|
var test = function(input) {
|
||||||
|
return function() {
|
||||||
|
Uglify.parse(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var fail = function(e) {
|
||||||
|
return e instanceof Uglify.JS_Parse_Error &&
|
||||||
|
e.message === "Unexpected line terminator";
|
||||||
|
}
|
||||||
|
for (var i = 0; i < inputs.length; i++) {
|
||||||
|
assert.throws(test(inputs[i]), fail);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user