git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 19, 2009, 21:40 UTC
Message-ID
<200911192240.27743.jnareb@gmail.com>
In-Reply-To
<1258659887-5244-2-git-send-email-bebarino@gmail.com>
On Thu, 19 Nov 2009, Stephen Boyd wrote:
Show 8 quoted lines
> Currently handleLine() assumes that a commit author name will always
> start with a capital letter. It's possible that the author name is
> user@example.com 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 <bebarino@gmail.com>
Acked-by: Jakub Narebski <jnareb@gmail.com>
> ---
[From "[PATCH 0/2] jn/gitweb-blame fixes"]
Show 5 quoted lines
> 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?

Show 21 quoted lines
>  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
Previous: Stephen BoydNext: Stephen Boyd
Message 3 of 41 in “jn/gitweb-blame fixes”
  1. 0/2 jn/gitweb-blame fixesStephen Boyd, Nov 19, 2009
  2. 1/2 gitweb.js: fix null object exception in initials calculationStephen Boyd, Nov 19, 2009
  3. Jakub NarebskiNov 19, 2009
  4. Stephen BoydNov 19, 2009
  5. 2/2 gitweb.js: use unicode encoding for nbsp instead of html entityStephen Boyd, Nov 19, 2009
  6. Jakub NarebskiNov 19, 2009
  7. Stephen BoydNov 20, 2009
  8. 2/2 gitweb.js: fix padLeftStr() and its usageStephen Boyd, Nov 25, 2009
  9. Jakub NarebskiNov 19, 2009
  10. Stephen BoydNov 20, 2009
  11. Stephen BoydNov 20, 2009
  12. Jakub NarebskiNov 21, 2009
  13. Jakub NarebskiNov 21, 2009
  14. gitweb.js: Harden setting blamed commit info in incremental blameJakub Narebski, Nov 25, 2009
  15. Nanako ShiraishiNov 25, 2009
  16. Jakub NarebskiNov 25, 2009
  17. Stephen BoydNov 25, 2009
  18. Jakub NarebskiNov 25, 2009
  19. Jakub NarebskiNov 25, 2009
  20. Junio C HamanoNov 25, 2009
  21. Jakub NarebskiNov 25, 2009
  22. Junio C HamanoNov 26, 2009
  23. Jakub NarebskiNov 26, 2009
  24. gitweb: Make linking to actions requiring JavaScript a featureJakub Narebski, Nov 26, 2009
  25. Junio C HamanoNov 26, 2009
  26. Jakub NarebskiNov 26, 2009
  27. Junio C HamanoNov 27, 2009
  28. Jakub NarebskiNov 27, 2009
  29. Junio C HamanoNov 27, 2009
  30. Junio C HamanoDec 1, 2009
  31. Jakub NarebskiDec 1, 2009
  32. 1/2 gitweb: Make linking to actions requiring JavaScript a featureJakub Narebski, Dec 1, 2009
  33. 2/2 gitweb: Add link to other blame implementation in blame viewsJakub Narebski, Dec 1, 2009
  34. Stephen BoydDec 7, 2009
  35. Stephen BoydDec 7, 2009
  36. PATCH/RFC] gitweb.js: Workaround for IE8 bugJakub Narebski, Dec 8, 2009
  37. Stephen BoydDec 8, 2009
  38. Jakub NarebskiDec 8, 2009
  39. Jakub NarebskiDec 8, 2009
  40. Stephen BoydDec 9, 2009
  41. Stephen BoydNov 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.