Subject: Re: [PATCH 1/2] gitweb.js: fix null object exception in initials calculation

From: Jakub Narebski <[email-masked]>
Date: Thu, 19 Nov 2009 22:40:26 +0100

On Thu, 19 Nov 2009, Stephen Boyd wrote:

> Currently handleLine() assumes that a commit author name will always
> start with a capital letter. It's possible that the author name is
> [email-masked] and therefore calling a match() on the name will fail
> to return any matches. Subsequently joining these matches will cause an
> exception. Fix by checking that we have a match before trying to join
> the results into a set of initials for the author.
> 
> Signed-off-by: Stephen Boyd <[email-masked]>

Acked-by: Jakub Narebski <[email-masked]>

> ---

[From "[PATCH 0/2] jn/gitweb-blame fixes"]
> This series is based on next's jn/gitweb-blame branch.
>
> I was trying out the incremental blame and noticed it didn't work
> each time. The first patch fixes the crashing I experience when
> blaming gitweb.perl (ironic ;-)

Hmmm... gitweb/gitweb.perl *was* one of files I have tested 
'blame_incremental' view on, but I have not experienced any
crashes.

Perhaps it was the matter of different JavaScript engine (Mozilla 1.7.12
with Gecko/20050923 engine, Konqueror 3.5.3-0.2.fc4), or different
starting point for blame.

I assume that crashing lead simply to not working blame, not to browser
crash?

>  gitweb/gitweb.js |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/gitweb/gitweb.js b/gitweb/gitweb.js
> index 22570f5..02454d8 100644
> --- a/gitweb/gitweb.js
> +++ b/gitweb/gitweb.js
> @@ -532,8 +532,11 @@ function handleLine(commit, group) {
>  			if (group.numlines >= 2) {
>  				var fragment = document.createDocumentFragment();
>  				var br   = document.createElement("br");
> -				var text = document.createTextNode(
> -					commit.author.match(/\b([A-Z])\B/g).join(''));
> +				var match = commit.author.match(/\b([A-Z])\B/g);
> +				if (match) {
> +					var text = document.createTextNode(
> +							match.join(''));
> +				}
>  				if (br && text) {
>  					var elem = fragment || td_sha1;
>  					elem.appendChild(br);

Thanks.  It now corresponds to what it is done for ordinary 'blame'
view, i.e.:

	my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
	if (@author_initials) {
		print "<br />" .
		      esc_html(join('', @author_initials));
		#           or join('.', ...)
	}

P.S. Unfortunately unless we decide to generate JavaScript from Perl code,
using something like GWT for Java or Pylons for Python, e.g. CGI::Ajax
(which is not in Perl core), we would have to have such code duplication.

-- 
Jakub Narebski
Poland