gitweb: use decode_utf8 directly
Using decode() tries to decode data that is already UTF-8 and borks, but decode_utf8 from Encode.pm has a built-in safety against that. Signed-off-by: Junio C Hamano <junkio@cox.net>
Ismail Dönmez committed
May 2, 2007 at 00:12 UTC
e3ad95a8be82663d27cb501eaf9bad86a30f9cda
1 file changed
+10
-16
gitweb/gitweb.perl
+10
-16
@@ -560,12 +560,6 @@ sub validate_refname {
560
return $input;
561
}
562
563
-# very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
564
-sub to_utf8 {
565
- my $str = shift;
566
- return decode("utf8", $str, Encode::FB_DEFAULT);
567
-}
568
-
563
# quote unsafe chars, but keep the slash, even when it's not
564
# correct, but quoted slashes look too horrible in bookmarks
565
sub esc_param {
@@ -590,7 +584,7 @@ sub esc_html ($;%) {
584
my $str = shift;
585
my %opts = @_;
586
593
- $str = to_utf8($str);
587
+ $str = decode_utf8($str);
588
$str = $cgi->escapeHTML($str);
589
if ($opts{'-nbsp'}) {
590
$str =~ s/ / /g;
@@ -604,7 +598,7 @@ sub esc_path {
598
my $str = shift;
599
my %opts = @_;
600
607
- $str = to_utf8($str);
601
+ $str = decode_utf8($str);
602
$str = $cgi->escapeHTML($str);
603
if ($opts{'-nbsp'}) {
604
$str =~ s/ / /g;
@@ -887,7 +881,7 @@ sub format_subject_html {
881
882
if (length($short) < length($long)) {
883
return $cgi->a({-href => $href, -class => "list subject",
890
- -title => to_utf8($long)},
884
+ -title => decode_utf8($long)},
885
esc_html($short) . $extra);
886
} else {
887
return $cgi->a({-href => $href, -class => "list subject"},
@@ -1104,7 +1098,7 @@ sub git_get_projects_list {
1098
if (check_export_ok("$projectroot/$path")) {
1099
my $pr = {
1100
path => $path,
1107
- owner => to_utf8($owner),
1101
+ owner => decode_utf8($owner),
1102
};
1103
push @list, $pr
1104
}
@@ -1133,7 +1127,7 @@ sub git_get_project_owner {
1127
$pr = unescape($pr);
1128
$ow = unescape($ow);
1129
if ($pr eq $project) {
1136
- $owner = to_utf8($ow);
1130
+ $owner = decode_utf8($ow);
1131
last;
1132
}
1133
}
@@ -1607,7 +1601,7 @@ sub get_file_owner {
1601
}
1602
my $owner = $gcos;
1603
$owner =~ s/[,;].*$//;
1610
- return to_utf8($owner);
1604
+ return decode_utf8($owner);
1605
}
1606
1607
## ......................................................................
@@ -1690,7 +1684,7 @@ sub git_header_html {
1684
1685
my $title = "$site_name";
1686
if (defined $project) {
1693
- $title .= " - " . to_utf8($project);
1687
+ $title .= " - " . decode_utf8($project);
1688
if (defined $action) {
1689
$title .= "/$action";
1690
if (defined $file_name) {
@@ -1963,7 +1957,7 @@ sub git_print_page_path {
1957
1958
print "<div class=\"page_path\">";
1959
print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
1966
- -title => 'tree root'}, to_utf8("[$project]"));
1960
+ -title => 'tree root'}, decode_utf8("[$project]"));
1961
print " / ";
1962
if (defined $name) {
1963
my @dirname = split '/', $name;
@@ -2578,7 +2572,7 @@ sub git_project_list_body {
2572
($pr->{'age'}, $pr->{'age_string'}) = @aa;
2573
if (!defined $pr->{'descr'}) {
2574
my $descr = git_get_project_description($pr->{'path'}) || "";
2581
- $pr->{'descr_long'} = to_utf8($descr);
2575
+ $pr->{'descr_long'} = decode_utf8($descr);
2576
$pr->{'descr'} = chop_str($descr, 25, 5);
2577
}
2578
if (!defined $pr->{'owner'}) {
@@ -3610,7 +3604,7 @@ sub git_snapshot {
3604
$hash = git_get_head_hash($project);
3605
}
3606
3613
- my $filename = to_utf8(basename($project)) . "-$hash.tar.$suffix";
3607
+ my $filename = decode_utf8(basename($project)) . "-$hash.tar.$suffix";
3608
3609
print $cgi->header(
3610
-type => "application/$ctype",