# [PATCH] gitweb: Call to_utf8() on input string in chop_and_escape_str()

3 messages from 2011-11-29 to 2011-11-29. Participants: Jürgen Kreileder, Jakub Narebski.
Thread: https://gitlist.dev/t/29045

## Jürgen Kreileder, 2011-11-29 21:41

Subject: [PATCH] gitweb: Call to_utf8() on input string in chop_and_escape_str()
Message-ID: <CAKD0Uuy8y7Dc6gfvYVe-FJ=Reiu0M3wOY4r4VVPtEYmahZcdwA@mail.gmail.com>
URL: https://gitlist.dev/e/CAKD0Uuy8y7Dc6gfvYVe-FJ%3DReiu0M3wOY4r4VVPtEYmahZcdwA%40mail.gmail.com

```
a) To fix the comparison with the chopped string
b) To give the title attribute correct encoding

Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
---
 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 4f0c3bd..4237ea6 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1695,11 +1695,11 @@ sub chop_and_escape_str {
 	my ($str) = @_;

 	my $chopped = chop_str(@_);
-	if ($chopped eq $str) {
+	if ($chopped eq to_utf8($str)) {
 		return esc_html($chopped);
 	} else {
 		$str =~ s/[[:cntrl:]]/?/g;
-		return $cgi->span({-title=>$str}, esc_html($chopped));
+		return $cgi->span({-title => to_utf8($str)}, esc_html($chopped));
 	}
 }

-- 
1.7.5.4

```

## Jakub Narebski, 2011-11-29 21:50

Subject: Re: [PATCH] gitweb: Call to_utf8() on input string in chop_and_escape_str()
Message-ID: <201111292250.04800.jnareb@gmail.com>
URL: https://gitlist.dev/e/201111292250.04800.jnareb%40gmail.com
In-Reply-To: <CAKD0Uuy8y7Dc6gfvYVe-FJ=Reiu0M3wOY4r4VVPtEYmahZcdwA@mail.gmail.com>

```
Jürgen Kreileder wrote:

> a) To fix the comparison with the chopped string
> b) To give the title attribute correct encoding
> 
> Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
> ---
>  gitweb/gitweb.perl |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 4f0c3bd..4237ea6 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -1695,11 +1695,11 @@ sub chop_and_escape_str {
>  	my ($str) = @_;

Why not simply

  	my $str = to_utf8(shift);
 
>  	my $chopped = chop_str(@_);
> -	if ($chopped eq $str) {
> +	if ($chopped eq to_utf8($str)) {
>  		return esc_html($chopped);
>  	} else {
>  		$str =~ s/[[:cntrl:]]/?/g;
> -		return $cgi->span({-title=>$str}, esc_html($chopped));
> +		return $cgi->span({-title => to_utf8($str)}, esc_html($chopped));
>  	}
>  }
> 
> -- 
> 1.7.5.4
> 

-- 
Jakub Narebski
Poland

```

## Jürgen Kreileder, 2011-11-29 22:14

Subject: Re: [PATCH] gitweb: Call to_utf8() on input string in chop_and_escape_str()
Message-ID: <CAKD0Uuw64bRryYpVbp0G7HNjZHgHUsnSMH3g3gWF-Jv9dWA04Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAKD0Uuw64bRryYpVbp0G7HNjZHgHUsnSMH3g3gWF-Jv9dWA04Q%40mail.gmail.com
In-Reply-To: <201111292250.04800.jnareb@gmail.com>

```
On Tue, Nov 29, 2011 at 22:50, Jakub Narebski <jnareb@gmail.com> wrote:
> Jürgen Kreileder wrote:
>
>> a) To fix the comparison with the chopped string
>> b) To give the title attribute correct encoding
>>
>> Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
>> ---
>>  gitweb/gitweb.perl |    4 ++--
>>  1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>> index 4f0c3bd..4237ea6 100755
>> --- a/gitweb/gitweb.perl
>> +++ b/gitweb/gitweb.perl
>> @@ -1695,11 +1695,11 @@ sub chop_and_escape_str {
>>       my ($str) = @_;
>
> Why not simply
>
>        my $str = to_utf8(shift);
>

Good question.  Because I thought it broke something when I tested it.
I can't reproduce that now, though.  Might have been something unrelated.
So:

-- >8 --
Subject: [PATCH] gitweb: Call to_utf8() on input string in
 chop_and_escape_str()

a) To fix the comparison with the chopped string
b) To give the title attribute correct encoding

Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
---
 gitweb/gitweb.perl |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index bfada0e..036ae46 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1699,6 +1699,7 @@ sub chop_and_escape_str {
 	my ($str) = @_;

 	my $chopped = chop_str(@_);
+	$str = to_utf8($str);
 	if ($chopped eq $str) {
 		return esc_html($chopped);
 	} else {
-- 
1.7.5.4

```
