Patchwork [STABLE] hgweb: add missing semicolon

login
register
mail settings
Submitter Takumi IINO
Date Oct. 24, 2013, 12:41 p.m.
Message ID <5199ace8a65968252c2f.1382618487@iino-no-MacBook-Air.local>
Download mbox | patch
Permalink /patch/2814/
State Accepted
Commit 80aa912dcb2d71c2f9dc41db6f0db1dd43fb01a1
Headers show

Comments

Takumi IINO - Oct. 24, 2013, 12:41 p.m.
# HG changeset patch
# User Takumi IINO <trot.thunder@gmail.com>
# Date 1382618233 -32400
#      Thu Oct 24 21:37:13 2013 +0900
# Branch stable
# Node ID 5199ace8a65968252c2fca9e9712e2ffaf47361c
# Parent  b7f76db06dc0f1c85f05256eaba7ac7559e811e9
hgweb: add missing semicolon
Matt Mackall - Oct. 25, 2013, 8:20 p.m.
On Thu, 2013-10-24 at 21:41 +0900, Takumi IINO wrote:
> # HG changeset patch
> # User Takumi IINO <trot.thunder@gmail.com>
> # Date 1382618233 -32400
> #      Thu Oct 24 21:37:13 2013 +0900
> # Branch stable
> # Node ID 5199ace8a65968252c2fca9e9712e2ffaf47361c
> # Parent  b7f76db06dc0f1c85f05256eaba7ac7559e811e9
> hgweb: add missing semicolon

Queued for stable, thanks. What impact did this have?
Martin Geisler - Oct. 25, 2013, 9:57 p.m.
Matt Mackall <mpm@selenic.com> writes:

> On Thu, 2013-10-24 at 21:41 +0900, Takumi IINO wrote:
>> # HG changeset patch
>> # User Takumi IINO <trot.thunder@gmail.com>
>> # Date 1382618233 -32400
>> #      Thu Oct 24 21:37:13 2013 +0900
>> # Branch stable
>> # Node ID 5199ace8a65968252c2fca9e9712e2ffaf47361c
>> # Parent  b7f76db06dc0f1c85f05256eaba7ac7559e811e9
>> hgweb: add missing semicolon
>
> Queued for stable, thanks. What impact did this have?

I doesn't make a difference here. JavaScript has optional semi-colons,
in the sense that the parser inserts semi-colons when it find an
unexpected token following a newline -- effectively turning the newline
into a semi-colon.

For statements like in our code, the semi-colons are optional:

    var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1];
    var data = JSON.parse(dataStr);

But there are some more or less pathological corner cases where a
missing semi-colon causes problems. The one more or less realistic case
I know is code like this:

    var x = "Hello" + y
    (a + b).someMethod()

This is parsed as

    var x = "Hello" + y(a + b).someMethod()

See these pages for more info:

  http://mislav.uniqpath.com/2010/05/semicolons/
  http://bclary.com/2004/11/07/#a-7.9

Patch

diff --git a/mercurial/templates/static/mercurial.js b/mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js
+++ b/mercurial/templates/static/mercurial.js
@@ -399,7 +399,7 @@ 
                         graph.canvas.height = addHeight;
 
                         var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1];
-                        var data = JSON.parse(dataStr)
+                        var data = JSON.parse(dataStr);
                         if (data.length < nextPageVar) {
                             nextPageVar = undefined;
                         }