[Pkg-javascript-commits] [uglifyjs] 100/228: Correctly raise a parse exception with a missing loop body (#1585)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 93cdb194f4895384b68a66736366659c39caece8
Author: Michael Mior <michael.mior at gmail.com>
Date:   Thu Mar 9 14:08:43 2017 -0500

    Correctly raise a parse exception with a missing loop body (#1585)
---
 lib/parse.js                       |  2 ++
 test/input/invalid/loop-no-body.js |  1 +
 test/mocha/cli.js                  | 13 +++++++++++++
 3 files changed, 16 insertions(+)

diff --git a/lib/parse.js b/lib/parse.js
index 9aadc9f..5e14086 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -787,6 +787,8 @@ function parse($TEXT, options) {
         return function() {
             var start = S.token;
             var expr = parser();
+            if (!expr) croak("Expected expression");
+
             var end = prev();
             expr.start = start;
             expr.end = end;
diff --git a/test/input/invalid/loop-no-body.js b/test/input/invalid/loop-no-body.js
new file mode 100644
index 0000000..07b2742
--- /dev/null
+++ b/test/input/invalid/loop-no-body.js
@@ -0,0 +1 @@
+for (var i = 0; i < 1; i++) 
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index e8e07cb..0b4fe00 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -238,4 +238,17 @@ describe("bin/uglifyjs", function () {
             done();
         });
     });
+    it("Should fail with a missing loop body", function(done) {
+        var command = uglifyjscmd + ' test/input/invalid/loop-no-body.js';
+
+        exec(command, function (err, stdout, stderr) {
+            assert.ok(err);
+            var lines = stderr.split(/\n/);
+            assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0");
+            assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) ");
+            assert.strictEqual(lines[2], "                            ^");
+            assert.strictEqual(lines[3], "SyntaxError: Expected expression");
+            done();
+        });
+    });
 });

-- 
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