Entries from April 2007 ↓

A Short Trip To Coorg

We started early (if 6:30 AM can be called that) for the Coorg trip. By noon, we were already driving (being driven) on the lush, serpentine, hilly roads. The weather was bearably warm, though it tended to get very humid during the evening. Great gray clouds were seen rolling over distant, misty hills. But their destination was obviously some other faraway land. Learned from the coffee estate owners there that the rains have eluded Coorg so far and most of them have had to rely on the brooks/streams/ponds in their estate to water their plantations.

Saw coffee plants for the first time and learned to distinguish between the Arabica and the Robusta varieties. Saw how cardamom and pepper are grown and sampled a bit of both right off their respective plants! Saw a water fall (Abbey falls) and walked till the microbes living on my skin thought that they were inhabiting one.

Abbey Falls

We started back for Bangalore quite late (if 11:30 AM can be called that). The shortcut our driver took, brought us on a patch that was being tarred afresh. A complete stranger came to our rescue and allowed us to take the car through a dirt-track that ran through his estate. Some 40 km later we were stranded in a jam caused by a tree that had just been felled to broaden the road.

By the time we hit the Mysore-Bangalore highway, it was so hot that we could see mirages on the road. As a car would race ahead of us, we would see it reflect in a non-existent puddle of water on the road; half expecting it to cause a splash. My wife recounted an old cartoon she had seen on TV about an Arab and his camel stranded in a desert. They chase mirage after mirage and get so disappointed that when they actually stumble upon water in an oasis, such is their disbelief, that they walk right into it and drown. Just the sort of note I should end this brief travelogue on!

Related Posts:
Notes from a Coorg visit in June’09
Yet another short visit to Coorg (Apr’09)

ASP.NET Stripping Accented Characters?

A friend who runs shortext.com pinged me with an interesting question one evening. People posting messages to his website via a Firefox plugin that he had written for twitter, were reporting that all accented characters in their posts (like éåüç), were being stripped out. For instance, each time someone posted café, all that came through was caf. I asked him for the problematic querystring/post data and here is what it looked like (server name changed to localhost):

http://localhost/default.aspx?message=caf%E9

Doing a Response.Write(Request.QueryString["message"]); got us:

caf

(Page’s encoding set to utf8, ASP.NET 2.0, IIS 6 on Windows Server 2003).

The result was consistent across all browsers.

Response.Write(Request.RawUrl);

got us:

/wwwroot/Default.aspx?message=caf%E9

Obviously, the browser was letting the querystring untouched. It was the ASP.NET infrastructure that was intervening while parsing the querystring.How about Server.UrlDecode, we thought. This is what we got:

Response.Write(Server.UrlDecode(Request.RawUrl));

/wwwroot/Default.aspx?message=caf

Time for some extreme measures. We added a reference to Microsoft.JScript and used

Response.Write(Microsoft.JScript.GlobalObject.unescape(Request.RawUrl)); which got us:

/wwwroot/Default.aspx?message=café

While this solved the problem, it meant that we would need to parse the QueryString by hand. And I had a nagging feeling that we were solving the wrong problem here. It then dawned on me that our URL was not encoded as utf8! Every character other than the first 128 ASCII characters takes up at least two bytes when encoded to utf8. Our é was encoded to E9, which is just one byte (or rather is 00E9 – Unicode but not utf8 encoded).

The next logical thing was to find out how we got this URL in the first place. It so happens, that we were using Javascript’s escape() method on the client to encode our URL. Changing that to encodeURIComponent gave us caf%C3%A9.

http://localhost/default.aspx?message=caf%C3%A9

Doing a Response.Write(Request.QueryString["message"]); now got us:

café

and all was well again with our world. Moral of the story, if you find that ASP.NET is stripping accented characters from your querystring, check that your data is encoded correctly as UTF8.