# [PATCH] Use &#160; instead of &nbsp; for XHTML compliance

5 messages from 2009-04-15 to 2009-04-15. Participants: Todd Zullinger, Mike Hommey, Jakub Narebski, Ricky Zhou.
Thread: https://gitlist.dev/t/18882

## Todd Zullinger, 2009-04-15 15:40

Subject: [PATCH] Use &#160; instead of &nbsp; for XHTML compliance
Message-ID: <20090415154012.GX13966@inocybe.teonanacatl.org>
URL: https://gitlist.dev/e/20090415154012.GX13966%40inocybe.teonanacatl.org

```
From: Ricky Zhou <ricky@fedoraproject.org>
---

This was noticed by the Fedora Infrastructure folks.  The pages
rendered fine in Firefox, but caused an XML error when run through tor
and privoxy together.  Part of this problem description may belong in
the commit message -- I was hesitant to add it, as I didn't read all
of the IRC log where the problem was noticed and debugged.

 gitweb/gitweb.perl |   40 ++++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 33ef190..55b56f7 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1042,8 +1042,8 @@ sub esc_html ($;%) {
 
 	$str = to_utf8($str);
 	$str = $cgi->escapeHTML($str);
-	if ($opts{'-nbsp'}) {
-		$str =~ s/ /&nbsp;/g;
+	if ($opts{'-subspaces'}) {
+		$str =~ s/ /&#160;/g;
 	}
 	$str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
 	return $str;
@@ -1056,8 +1056,8 @@ sub esc_path {
 
 	$str = to_utf8($str);
 	$str = $cgi->escapeHTML($str);
-	if ($opts{'-nbsp'}) {
-		$str =~ s/ /&nbsp;/g;
+	if ($opts{'-subspaces'}) {
+		$str =~ s/ /&#160;/g;
 	}
 	$str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
 	return $str;
@@ -1383,7 +1383,7 @@ sub file_type_long {
 sub format_log_line_html {
 	my $line = shift;
 
-	$line = esc_html($line, -nbsp=>1);
+	$line = esc_html($line, -subspaces=>1);
 	$line =~ s{\b([0-9a-fA-F]{8,40})\b}{
 		$cgi->a({-href => href(action=>"object", hash=>$1),
 					-class => "text"}, $1);
@@ -1710,7 +1710,7 @@ sub format_diff_line {
 			                     -class=>"list"}, $to_text);
 		}
 		$line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
-		        "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
+		        "<span class=\"section\">" . esc_html($section, -subspaces=>1) . "</span>";
 		return "<div class=\"diff$diff_class\">$line</div>\n";
 	} elsif ($from && $to && $line =~ m/^\@{3}/) {
 		my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
@@ -1743,10 +1743,10 @@ sub format_diff_line {
 			$line .= $to_text;
 		}
 		$line .= " $prefix</span>" .
-		         "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
+		         "<span class=\"section\">" . esc_html($section, -subspaces=>1) . "</span>";
 		return "<div class=\"diff$diff_class\">$line</div>\n";
 	}
-	return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
+	return "<div class=\"diff$diff_class\">" . esc_html($line, -subspaces=>1) . "</div>\n";
 }
 
 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
@@ -2101,9 +2101,9 @@ sub git_populate_project_tagcloud {
 			# Pad the title with spaces so that the cloud looks
 			# less crammed.
 			my $title = $ctags_lc{$_}->{topname};
-			$title =~ s/ /&nbsp;/g;
-			$title =~ s/^/&nbsp;/g;
-			$title =~ s/$/&nbsp;/g;
+			$title =~ s/ /&#160;/g;
+			$title =~ s/^/&#160;/g;
+			$title =~ s/$/&#160;/g;
 			$cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count});
 		}
 	} else {
@@ -3535,7 +3535,7 @@ sub git_difftree_body {
 			               -title => 'commitdiff to parent number ' .
 			                          ($i+1) . ': ' . substr($par,0,7)},
 			              $i+1) .
-			      "&nbsp;</th>\n";
+			      "&#160;</th>\n";
 		}
 		print "</tr></thead>\n<tbody>\n";
 	}
@@ -4275,7 +4275,7 @@ sub git_tags_body {
 		if ($tag{'type'} eq "tag") {
 			print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
 		} else {
-			print "&nbsp;";
+			print "&#160;";
 		}
 		print "</td>\n" .
 		      "<td class=\"link\">" . " | " .
@@ -4491,7 +4491,7 @@ sub git_summary {
 	git_header_html();
 	git_print_page_nav('summary','', $head);
 
-	print "<div class=\"title\">&nbsp;</div>\n";
+	print "<div class=\"title\">&#160;</div>\n";
 	print "<table class=\"projects_list\">\n" .
 	      "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
 	      "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
@@ -4602,7 +4602,7 @@ sub git_tag {
 	my $comment = $tag{'comment'};
 	foreach my $line (@$comment) {
 		chomp $line;
-		print esc_html($line, -nbsp=>1) . "<br/>\n";
+		print esc_html($line, -subspaces=>1) . "<br/>\n";
 	}
 	print "</div>\n";
 	git_footer_html();
@@ -4888,7 +4888,7 @@ sub git_blob {
 			$nr++;
 			$line = untabify($line);
 			printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
-			       $nr, $nr, $nr, esc_html($line, -nbsp=>1);
+			       $nr, $nr, $nr, esc_html($line, -subspaces=>1);
 		}
 	}
 	close $fd
@@ -5913,13 +5913,13 @@ sub git_search {
 			} else {
 				$ltext = untabify($ltext);
 				if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
-					$ltext = esc_html($1, -nbsp=>1);
+					$ltext = esc_html($1, -subspaces=>1);
 					$ltext .= '<span class="match">';
-					$ltext .= esc_html($2, -nbsp=>1);
+					$ltext .= esc_html($2, -subspaces=>1);
 					$ltext .= '</span>';
-					$ltext .= esc_html($3, -nbsp=>1);
+					$ltext .= esc_html($3, -subspaces=>1);
 				} else {
-					$ltext = esc_html($ltext, -nbsp=>1);
+					$ltext = esc_html($ltext, -subspaces=>1);
 				}
 				print "<div class=\"pre\">" .
 					$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
-- 
1.6.0.6

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To have a successful relationship, I must learn to make it look like
I'm giving as much as I'm getting.

```

## Mike Hommey, 2009-04-15 15:50

Subject: Re: [PATCH] Use &#160; instead of &nbsp; for XHTML compliance
Message-ID: <20090415155013.GA15518@glandium.org>
URL: https://gitlist.dev/e/20090415155013.GA15518%40glandium.org
In-Reply-To: <20090415154012.GX13966@inocybe.teonanacatl.org>

```
On Wed, Apr 15, 2009 at 11:40:12AM -0400, Todd Zullinger <tmz@pobox.com> wrote:
> From: Ricky Zhou <ricky@fedoraproject.org>
> ---
> 
> This was noticed by the Fedora Infrastructure folks.  The pages
> rendered fine in Firefox, but caused an XML error when run through tor
> and privoxy together.  Part of this problem description may belong in
> the commit message -- I was hesitant to add it, as I didn't read all
> of the IRC log where the problem was noticed and debugged.

&nbsp; is very much xhtml compliant, so the problem must lie somewhere
else, possibly in privoxy.

Mike

```

## Jakub Narebski, 2009-04-15 15:55

Subject: Re: [PATCH] Use &#160; instead of &nbsp; for XHTML compliance
Message-ID: <200904151755.07425.jnareb@gmail.com>
URL: https://gitlist.dev/e/200904151755.07425.jnareb%40gmail.com
In-Reply-To: <20090415154012.GX13966@inocybe.teonanacatl.org>

```
On Wed, 15 April 2009, Todd Zullinger wrote:

> From: Ricky Zhou <ricky@fedoraproject.org>
> ---
> 
> This was noticed by the Fedora Infrastructure folks.  The pages
> rendered fine in Firefox, but caused an XML error when run through tor
> and privoxy together.  Part of this problem description may belong in
> the commit message -- I was hesitant to add it, as I didn't read all
> of the IRC log where the problem was noticed and debugged.

Wouldn't it be a better solution to add DTD with HTML entities if/when
gitweb serves XHTML 1.0 together application/xhtml+xml mimetype, instead
of unconditionally using what is I think worse solution? Especially that
error is I think quite rare situation and/or bug in browser...

I also don't think that the change -nbsp => -subspaces is necessary;
it causes large code churn for nothing, and name is IMVHO worse.
It is about nonbreakable and non-compactable space.

> 
>  gitweb/gitweb.perl |   40 ++++++++++++++++++++--------------------
>  1 files changed, 20 insertions(+), 20 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 33ef190..55b56f7 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -1042,8 +1042,8 @@ sub esc_html ($;%) {
>  
>  	$str = to_utf8($str);
>  	$str = $cgi->escapeHTML($str);
> -	if ($opts{'-nbsp'}) {
> -		$str =~ s/ /&nbsp;/g;
> +	if ($opts{'-subspaces'}) {
> +		$str =~ s/ /&#160;/g;
>  	}
>  	$str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
>  	return $str;

-- 
Jakub Narebski
Poland

```

## Ricky Zhou, 2009-04-15 16:21

Subject: Re: [PATCH] Use &#160; instead of &nbsp; for XHTML compliance
Message-ID: <20090415162123.GC3316@sphe.res.cmu.edu>
URL: https://gitlist.dev/e/20090415162123.GC3316%40sphe.res.cmu.edu
In-Reply-To: <200904151755.07425.jnareb@gmail.com>

```
On 2009-04-15 05:55:04 PM, Jakub Narebski wrote:
> Wouldn't it be a better solution to add DTD with HTML entities if/when
> gitweb serves XHTML 1.0 together application/xhtml+xml mimetype, instead
> of unconditionally using what is I think worse solution? Especially that
> error is I think quite rare situation and/or bug in browser...
> 
> I also don't think that the change -nbsp => -subspaces is necessary;
> it causes large code churn for nothing, and name is IMVHO worse.
> It is about nonbreakable and non-compactable space.
Sorry, as Mike mentioned, I was mistaken about the validity of &nbsp;.
I'm going to try to reproduce this myself so I can look more into what
actually caused the error.

Thanks,
Ricky

```

## Ricky Zhou, 2009-04-15 16:38

Subject: Re: [PATCH] Use &#160; instead of &nbsp; for XHTML compliance
Message-ID: <20090415163829.GD3316@sphe.res.cmu.edu>
URL: https://gitlist.dev/e/20090415163829.GD3316%40sphe.res.cmu.edu
In-Reply-To: <20090415155013.GA15518@glandium.org>

```
On 2009-04-15 05:50:14 PM, Mike Hommey wrote:
> &nbsp; is very much xhtml compliant, so the problem must lie somewhere
> else, possibly in privoxy.
Sorry for the noise, I've confirmed that this only happens with
torbutton is used.  

Thanks,
Ricky

```
