[Mono-aspnet-list] url-decode failed with encoded shift_jis query

USAGI@WRP usagi at WonderRabbitProject.net
Wed May 27 10:10:38 EDT 2009

## this message contain multibyte charactor code.

Sometime, web client request with query used by url-encoded multibyte

example1: "紅茶"(utf-8) to "%e7%b4%85%e8%8c%b6"(url-encoded)
example2: "紅茶"(shift_jis) to "%8dg%92%83"(url-encoded)

# "紅茶" is Japanese charactors. It's "tea" in English.

In ASP.NET web server, it try url-decode and set property of
Request.QueryString automatically. But, mod_mono(2.4) failed decode from
url-encoded shift_jis string. It's not web.config or charactor setting

I tried the code:

using System.Text;
using System.Web;

var enc_utf8 = Encoding.UTF8;
var enc_sjis = Encoding.GetEncoding(932); // 932 is shift_jis code page

var utf8_string = "紅茶";
var utf8_bin = enc_utf8.GetBytes(utf8_string);
var sjis_bin = Encoding.Convert(enc_utf8, enc_sjis, utf8_bin);
var urlenc_string = HttpUtility.UrlEncode(sjis_bin); // equiv. some client
request query string.

var decoded_by_web = HttpUtility.UrlDecode(urlenc_string, enc_sjis); // it's
fail in Mono.(*1)

var urldec_bin = HttpUtility.UrlDecodeToBytes(urlenc_string, enc_sjis);
var decoded_by_enc = enc_sjis.GetString(urldec_bin); // it's OK.(*2)

int result = 0; // detect error and set flags
if (utf8_string != decoded_by_web) result += 1;
if (utf8_string != decoded_by_enc) result += 2;
System.Diagnostics.Debug.WriteLine(result); // or put any stream. and check

It run on the Windows system, put result "0". It's OK.
But, it run on the Mono, put result "1". It's fail. Also, on the mod_mono.

I think, there is this problem for implementation of
System.Web.HttpUtility.UrlDecode method, maybe. Because, it is no problems
with using binary decode and System.Text.Encoding(*2) on the Mono, or the
Windows systems.

This problem avoidable as previously indicated(*2), for now. But, I think
it's bug of Mono.

View this message in context: http://www.nabble.com/url-decode-failed-with-encoded-shift_jis-query-tp23743301p23743301.html
Sent from the Mono - ASP.NET mailing list archive at Nabble.com.

More information about the Mono-aspnet-list mailing list