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

[PATCH] Use perl builtin class utf8 for UTF-8 decoding

From
IDIsmail Dönmez <ismail@pardus.org.tr>
Date
Dec 5, 2007, 10:26 UTC
Message-ID
<200712051226.30162.ismail@pardus.org.tr>

Junio it would be very nice to get this in 1.5.4, fixes multiple problems and tested with many distros with success.

Use perl builtin class utf8 for UTF-8 decoding, this fixes Encode problems with older Encode and avoids problems on UTF-8 locales.

Signed-off-by: İsmail Dönmez <ismail@pardus.org.tr>
Acked-by: Jakub Narebski <jnareb@gmail.com>
Tested-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Tested-by: Wincent Colaiuta <win@wincent.com>
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index ff5daa7..db255c1 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -695,10 +695,9 @@ sub validate_refname {
 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
 sub to_utf8 {
 	my $str = shift;
-	my $res;
-	eval { $res = decode_utf8($str, Encode::FB_CROAK); };
-	if (defined $res) {
-		return $res;
+        if (utf8::valid($str)) {
+                utf8::decode($str);
+                return $str;
 	} else {
 		return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
 	}
-- 
Never learn by your mistakes, if you do you may never dare to try again.
Next: Junio C Hamano
Message 1 of 2 in “Use perl builtin class utf8 for UTF-8 decoding”
  1. Use perl builtin class utf8 for UTF-8 decodingIsmail Dönmez, Dec 5, 2007
  2. Junio C HamanoDec 5, 2007

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.