From 7ecf0501bb1439c77255ad0808abbe3141cf4bc7 Mon Sep 17 00:00:00 2001 From: corvid Date: Tue, 4 Dec 2012 19:56:03 +0000 Subject: form submission: try to transliterate data Unilaterally changing user data is consistently a bad idea, but when browser users aren't given any idea what they are permitted to type, it's better than leaving out the chars, or replacing with '?' or whatever. --- src/form.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/form.cc b/src/form.cc index 96fdbe27..cf608cfc 100644 --- a/src/form.cc +++ b/src/form.cc @@ -1056,7 +1056,18 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) iconv_t char_encoder = (iconv_t) -1; if (submit_charset && dStrAsciiCasecmp(submit_charset, "UTF-8")) { - char_encoder = iconv_open(submit_charset, "UTF-8"); + /* Some iconv implementations, given "//TRANSLIT", will do their best to + * transliterate the string. Under the circumstances, doing so is likely + * for the best. + */ + char *translit = dStrconcat(submit_charset, "//TRANSLIT", NULL); + + char_encoder = iconv_open(translit, "UTF-8"); + dFree(translit); + + if (char_encoder == (iconv_t) -1) + char_encoder = iconv_open(submit_charset, "UTF-8"); + if (char_encoder == (iconv_t) -1) { MSG_WARN("Cannot convert to character encoding '%s'\n", submit_charset); -- cgit v1.2.3