[Pkg-javascript-commits] [uglifyjs] 09/49: Legacy octal integer strict mode fixes
Jonas Smedegaard
dr at jones.dk
Fri Dec 9 11:43:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit 642273c29002e7676719f489d7fcf552974118f4
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date: Thu Jul 21 03:19:24 2016 +0200
Legacy octal integer strict mode fixes
---
lib/parse.js | 5 ++++-
test/mocha/number-literal.js | 24 ++++++++++++++++++++++++
test/mocha/string-literal.js | 2 +-
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/lib/parse.js b/lib/parse.js
index bd6f95f..ec82d47 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -349,6 +349,9 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
return is_alphanumeric_char(code);
});
if (prefix) num = prefix + num;
+ if (RE_OCT_NUMBER.test(num) && next_token.has_directive("use strict")) {
+ parse_error("SyntaxError: Legacy octal literals are not allowed in strict mode");
+ }
var valid = parse_js_number(num);
if (!isNaN(valid)) {
return token("num", valid);
@@ -392,7 +395,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
// Parse
if (ch === "0") return "\0";
if (ch.length > 0 && next_token.has_directive("use strict"))
- parse_error("SyntaxError: Octal literals are not allowed in strict mode");
+ parse_error("SyntaxError: Legacy octal escape sequences are not allowed in strict mode");
return String.fromCharCode(parseInt(ch, 8));
}
diff --git a/test/mocha/number-literal.js b/test/mocha/number-literal.js
new file mode 100644
index 0000000..8e05574
--- /dev/null
+++ b/test/mocha/number-literal.js
@@ -0,0 +1,24 @@
+var assert = require("assert");
+var uglify = require("../../");
+
+describe("Number literals", function () {
+ it("Should not allow legacy octal literals in strict mode", function() {
+ var inputs = [
+ '"use strict";00;',
+ '"use strict"; var foo = 00;'
+ ];
+
+ var test = function(input) {
+ return function() {
+ uglify.parse(input);
+ }
+ }
+ var error = function(e) {
+ return e instanceof uglify.JS_Parse_Error &&
+ e.message === "SyntaxError: Legacy octal literals are not allowed in strict mode";
+ }
+ for (var i = 0; i < inputs.length; i++) {
+ assert.throws(test(inputs[i]), error, inputs[i]);
+ }
+ });
+});
\ No newline at end of file
diff --git a/test/mocha/string-literal.js b/test/mocha/string-literal.js
index fc4c427..eb9e6f1 100644
--- a/test/mocha/string-literal.js
+++ b/test/mocha/string-literal.js
@@ -49,7 +49,7 @@ describe("String literals", function() {
var error = function(e) {
return e instanceof UglifyJS.JS_Parse_Error &&
- e.message === "SyntaxError: Octal literals are not allowed in strict mode";
+ e.message === "SyntaxError: Legacy octal escape sequences are not allowed in strict mode";
}
for (var input in inputs) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list