aboutsummaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-03-26 12:43:25 -0700
committerJunio C Hamano <gitster@pobox.com>2013-03-26 12:43:25 -0700
commitd7cccbb3bb706b6a9eb13120e354a8487b4b3cfe (patch)
treed37ed5fcab7225fab97ab6e5e2096f54c1b50419 /utf8.c
parent307d68e275d21b7e54d464f1e372b33e9444fef2 (diff)
parent5c680be113ec8aca49ddfbe93a9f43684d3d261e (diff)
downloadgit-d7cccbb3bb706b6a9eb13120e354a8487b4b3cfe.tar.gz
git-d7cccbb3bb706b6a9eb13120e354a8487b4b3cfe.tar.xz
Merge branch 'jk/utf-8-can-be-spelled-differently' into maint
Some platforms and users spell UTF-8 differently; retry with the most official "UTF-8" when the system does not understand the user-supplied encoding name that are the common alternative spellings of UTF-8. * jk/utf-8-can-be-spelled-differently: utf8: accept alternate spellings of UTF-8
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/utf8.c b/utf8.c
index 1087870c5..8f6e84b7b 100644
--- a/utf8.c
+++ b/utf8.c
@@ -507,9 +507,25 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e
if (!in_encoding)
return NULL;
+
conv = iconv_open(out_encoding, in_encoding);
- if (conv == (iconv_t) -1)
- return NULL;
+ if (conv == (iconv_t) -1) {
+ /*
+ * Some platforms do not have the variously spelled variants of
+ * UTF-8, so let's fall back to trying the most official
+ * spelling. We do so only as a fallback in case the platform
+ * does understand the user's spelling, but not our official
+ * one.
+ */
+ if (is_encoding_utf8(in_encoding))
+ in_encoding = "UTF-8";
+ if (is_encoding_utf8(out_encoding))
+ out_encoding = "UTF-8";
+ conv = iconv_open(out_encoding, in_encoding);
+ if (conv == (iconv_t) -1)
+ return NULL;
+ }
+
out = reencode_string_iconv(in, strlen(in), conv);
iconv_close(conv);
return out;