From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Christopher M. Fuhrman" Subject: [PATCH/RFC] gitweb: highlight: strip non-printable characters via col(1) Date: Tue, 16 Aug 2011 11:16:44 -0700 Message-ID: <1313518605-26460-1-git-send-email-cfuhrman@panix.com> Cc: jnareb@gmail.com, cwilson@cdwilson.us, sylvain@abstraction.fr, "Christopher M. Fuhrman" To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Aug 16 20:33:17 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QtORw-0007DX-Tu for gcvg-git-2@lo.gmane.org; Tue, 16 Aug 2011 20:33:17 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752588Ab1HPSdM (ORCPT ); Tue, 16 Aug 2011 14:33:12 -0400 Received: from l2mail1.panix.com ([166.84.1.75]:49921 "EHLO l2mail1.panix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752078Ab1HPSdM (ORCPT ); Tue, 16 Aug 2011 14:33:12 -0400 X-Greylist: delayed 960 seconds by postgrey-1.27 at vger.kernel.org; Tue, 16 Aug 2011 14:33:11 EDT Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by l2mail1.panix.com (Postfix) with ESMTP id 46955FA for ; Tue, 16 Aug 2011 14:17:13 -0400 (EDT) Received: from vc75.vc.panix.com (vc75.vc.panix.com [166.84.7.75]) by mailbackend.panix.com (Postfix) with ESMTP id A4A25347E1; Tue, 16 Aug 2011 14:17:10 -0400 (EDT) X-Mailer: git-send-email 1.7.5.4 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: From: "Christopher M. Fuhrman" The current code, as is, passes control characters, such as form-feed (^L) to highlight which then passes it through to the browser. This will cause the browser to display one of the following warnings: Safari v5.1 (6534.50) & Google Chrome v13.0.782.112: This page contains the following errors: error on line 657 at column 38: PCDATA invalid Char value 12 Below is a rendering of the page up to the first error. Mozilla Firefox 3.6.19 & Mozilla Firefox 5.0: XML Parsing Error: not well-formed Location: http://path/to/git/repo/blah/blah Both errors were generated by gitweb.perl v1.7.3.4 w/ highlight 2.7 using arch/ia64/kernel/unwind.c from the Linux kernel. Strip non-printable control-characters by piping the output produced by git-cat-file(1) to col(1) as follows: git cat-file blob deadbeef314159 | col -bx | highlight Tested under OpenSuSE 11.4 & NetBSD 5.1 using perl 5.12.3 and perl 5.12.2 respectively using Safari, Firefox, and Google Chrome. Signed-off-by: Christopher M. Fuhrman --- For an example of this bug in action, see: * http://git.fuhrbear.com/~cfuhrman/?p=linux/.git;a=blob;f=arch/alpha/kernel/core_titan.c;h=219bf271c0ba2e5f2d668af707df57fbbd00ccfd;hb=HEAD * http://git.fuhrbear.com/~cfuhrman/?p=linux/.git;a=blob;f=arch/ia64/kernel/unwind.c;h=fed6afa2e8a9014e65229e51e64fa4b1c13cc284;hb=HEAD WRT the col(1) command, I've verified that the binary is installed in /usr/bin on OpenSuSE, NetBSD, OpenBSD, Solaris 10, and AIX. This patch assumes that /usr/bin is in $PATH. Cheers! gitweb/gitweb.perl | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 81dacf2..38d5d4e 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3656,6 +3656,7 @@ sub run_highlighter { close $fd; open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ". + "col -bx | ". quote_command($highlight_bin). " --replace-tabs=8 --fragment --syntax $syntax |" or die_error(500, "Couldn't open file or run syntax highlighter"); -- 1.7.5.4