# # # patch "charset.cc" # from [fe37c21b3438f983aae8f388e09c6dabe6139a03] # to [72968a86c41c24a69d0fc9f4e6b6ef4a22f3c57d] # # patch "idna/stringprep.h" # from [c232686c1f60171b4e783bb1807c98fbb1ea0c4f] # to [dec94e47c4c9ed31135f8437ae5eb3d146332328] # # patch "idna/toutf8.c" # from [accfe40aea541f6498312545cca41dc4c7b41c8f] # to [e1d0a00a489cc073784655354b76c0efa15284e4] # ============================================================ --- charset.cc fe37c21b3438f983aae8f388e09c6dabe6139a03 +++ charset.cc 72968a86c41c24a69d0fc9f4e6b6ef4a22f3c57d @@ -47,17 +47,13 @@ charset_convert(string const & src_chars dst = src; else { - string dst_charset_real(dst_charset); -#ifdef ICONV_TRANSLIT - if (best_effort) - dst_charset_real += "//TRANSLIT"; -#endif char * converted = stringprep_convert(src.c_str(), - dst_charset_real.c_str(), - src_charset.c_str()); + dst_charset.c_str(), + src_charset.c_str(), + best_effort); E(converted != NULL, F("failed to convert string from %s to %s: '%s'") - % src_charset % dst_charset_real % src); + % src_charset % dst_charset % src); dst = string(converted); free(converted); } ============================================================ --- idna/stringprep.h c232686c1f60171b4e783bb1807c98fbb1ea0c4f +++ idna/stringprep.h dec94e47c4c9ed31135f8437ae5eb3d146332328 @@ -201,7 +201,8 @@ extern "C" extern const char *stringprep_locale_charset (void); extern char *stringprep_convert (const char *str, const char *to_codeset, - const char *from_codeset); + const char *from_codeset, + int best_effort); extern char *stringprep_locale_to_utf8 (const char *str); extern char *stringprep_utf8_to_locale (const char *str); ============================================================ --- idna/toutf8.c accfe40aea541f6498312545cca41dc4c7b41c8f +++ idna/toutf8.c e1d0a00a489cc073784655354b76c0efa15284e4 @@ -120,7 +120,8 @@ stringprep_convert (const char *str, **/ char * stringprep_convert (const char *str, - const char *to_codeset, const char *from_codeset) + const char *to_codeset, const char *from_codeset, + int best_effort) { iconv_t cd; char *dest; @@ -132,7 +133,6 @@ stringprep_convert (const char *str, size_t outbuf_size; int have_error = 0; int len; - int best_effort = 0; if (strcmp (to_codeset, from_codeset) == 0) { @@ -144,12 +144,19 @@ stringprep_convert (const char *str, return p; } - char * bp = to_codeset + strlen(to_codeset); - if (bp - to_codeset >= 10 && memcmp(bp - 10, "//TRANSLIT", 10) == 0) - best_effort = 1; - fprintf(stderr, "UTF8: %d\nBest effort: %d\n", strcmp(from_codeset, "UTF-8") == 0, best_effort); - +#ifdef ICONV_TRANSLIT + if (best_effort) + { + char to_c[strlen (to_codeset) + 10]; + strcpy (to_c, to_codeset); + strcat (to_c, "//TRANSLIT"); + cd = iconv_open (to_c, from_codeset); + } + else + cd = iconv_open (to_codeset, from_codeset); +#else cd = iconv_open (to_codeset, from_codeset); +#endif if (cd == (iconv_t) - 1) return NULL; @@ -206,12 +213,7 @@ again: if ((*p & 0x80) == 0) char_len = 1; else if ((*p & 0x40) == 0) - { - fprintf(stderr, "Error: len 1.5\n"); - // ERROR: not allowed to begin a sequence! - have_error = 1; - break; - } + char_len = 1; // ERROR: not allowed to begin a sequence else if ((*p & 0x20) == 0) char_len = 2; else if ((*p & 0x10) == 0) @@ -220,14 +222,19 @@ again: char_len = 4; else if ((*p & 0x04) == 0) char_len = 5; - fprintf(stderr, "Char %d: len %d\n", len - inbytes_remaining, char_len); - //TODO check UTF-8 specs for length 5 & 6 + else if ((*p & 0x02) == 0) + char_len = 6; + else + char_len = 1; // ERROR: not used by UTF-8 if (char_len > inbytes_remaining) char_len = inbytes_remaining; p += char_len; inbytes_remaining -= char_len; - *outp++ = '?'; - --outbytes_remaining; + if (outbytes_remaining > 0) + { + *outp++ = '?'; + --outbytes_remaining; + } goto again; } break; @@ -267,11 +274,12 @@ stringprep_convert (const char *str, char * stringprep_convert (const char *str, - const char *to_codeset, const char *from_codeset) + const char *to_codeset, const char *from_codeset, + int best_effort) { char *p; fprintf (stderr, "libidn: warning: libiconv not installed, cannot " - "convert data to UTF-8\n"); + "convert data from %s to %s\n", from_codeset, to_codeset); p = malloc (strlen (str) + 1); if (!p) return NULL; @@ -294,7 +302,7 @@ stringprep_locale_to_utf8 (const char *s char * stringprep_locale_to_utf8 (const char *str) { - return stringprep_convert (str, "UTF-8", stringprep_locale_charset ()); + return stringprep_convert (str, "UTF-8", stringprep_locale_charset (), 0); } /** @@ -310,5 +318,5 @@ stringprep_utf8_to_locale (const char *s char * stringprep_utf8_to_locale (const char *str) { - return stringprep_convert (str, stringprep_locale_charset (), "UTF-8"); + return stringprep_convert (str, stringprep_locale_charset (), "UTF-8", 0); }