Bug 4303 - Hgweb Graph showing unrecognized charachters on some branch names.
Summary: Hgweb Graph showing unrecognized charachters on some branch names.
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: hgweb (show other bugs)
Version: 3.0.2
Hardware: PC All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-13 13:33 UTC by Stefano
Modified: 2014-07-15 14:22 UTC (History)
2 users (show)

See Also:
Python Version: ---


Attachments
Part of the source web page with invalid charachters. (321 bytes, text/html)
2014-07-13 13:33 UTC, Stefano
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefano 2014-07-13 13:33 UTC
Created attachment 1778 [details]
Part of the source web page with invalid charachters.

Mercurial 3.0.2 on Windows with TortoiseHg 3.0.2, Python 2.7.6

and also:

Mercurial 3.0.2 on Linux Ubuntu 12.04.
Server Version: Apache/2.2.22 (Ubuntu)
                mod_wsgi/3.3 Python/2.7.3
Other modules:  Phusion_Passenger/4.0.3 PHP/5.3.10-1ubuntu3.10 with Suhosin-Patch

When I try to browse a repository of mine, for some branches the name has several unknown charachters/question marks at the beginning, thus causing also the error:
"Error: SyntaxError: JSON.parse: bad control character in string literal at line 1 column 133 of the JSON data".
at the next AJAX request, scrolling the page from the point the branch "with the invalid chars" appears.

Stripping the involved branches in a local clone lets the hgweb graph page work correctly.

The same charachters appear to be be present in our Redmine repository interface (accesses the same repository), but only in the links to the involved branches.

Attached a part of the script in the web source page with the involved charachters (I have changed personal data).
Comment 1 Stefano 2014-07-13 13:36 UTC
I've tryed changing repository encoding in the hgweb settings file, but this does not seem to be related to that.

Please suggest me how to give more informations on the error if necessary.
Comment 2 Matt Mackall 2014-07-13 15:28 UTC
What is the output of 'hg branches'?
Comment 3 Stefano 2014-07-13 15:56 UTC
On Windows:

default                     1582:05a400c1987b
8.78.13.J                   1273:15a2e678ddfa
8.74.10.Z.20131122          1227:eb884c7cc1d5
8.76.12.12149RTL            1095:21370edc496d
8.76.31.20130912            1079:060bcaa31de4
8.76.27                     1042:b89b5ca9dae6
patch_messaggiErrore        1581:0d7d4c2ae514 (inactive)
        Integ_Compl_NTarat  1536:28e5f87f8a8e (inactive)

On Linux (SSH console via Putty):

default                     1580:05a400c1987b
8.78.13.J                   1271:15a2e678ddfa
8.74.10.Z.20131122          1225:eb884c7cc1d5
8.76.12.12149RTL            1095:21370edc496d
8.76.31.20130912            1079:060bcaa31de4
8.76.27                     1042:b89b5ca9dae6
Integ_Compl_NTarat  1534:28e5f87f8a8e (inactive)
Comment 4 Stefano 2014-07-13 15:58 UTC
Integ_Compl_NTarat  1536:28e5f87f8a8e (inactive) is the branch with the problem.

Didn't notice that on Windows there are spaces before the name. Pretty sure was not inserted like so.
Comment 5 Matt Mackall 2014-07-13 17:02 UTC
Looks like your branch name got prepended with 8 null bytes... and while Mercurial is happy to accept any valid UTF-8 you give it, JSON doesn't like null bytes.

Try again on Linux with:

$ hg branches | hexdump -C

This is almost certainly a sign of a memory glitch on one of your machines. Does the machine that made the commit have ECC memory?
Comment 6 Stefano 2014-07-13 17:19 UTC
I can confirm that there are 8 null chars before the name:

00000370  69 76 65 29 0a 00 00 00  00 00 00 00 00 49 6e 74  |ive).........Int|

The machine of the developer that did work on that branch is quite old and does not have ECC memory.
Comment 7 HG Bot 2014-07-14 20:00 UTC
Fixed by http://selenic.com/repo/hg/rev/829f2dd99f5c
Matt Mackall <mpm@selenic.com>
templates: escape NUL bytes in jsonescape (issue4303)

It's currently possible for various fields to contain NUL bytes, which
are disallowed in JSON.

(please test the fix)
Comment 8 Stefano 2014-07-15 08:41 UTC
Replaced templatefilters.py with the fixed one, works correctly, no JSON errors.
Comment 9 Matt Mackall 2014-07-15 14:22 UTC
Shiny.