Note that there are some explanatory texts on larger screens.

plurals
  1. POVS2005 UTF-8 generic HTTP handler: issues with certain chars in query string (e.g. þ æ)
    primarykey
    data
    text
    <p>I am developing a generic HTTP handler in VS2005 and testing it in Debug Mode. It works well except when the query string contains higher-bit characters, e.g. Latin Small Letter Thorn /u00FE <strong>þ</strong> and Latin Small Letter Ae /u00E6 <strong>æ</strong>.</p> <p>IE8 on my machine is set to send UTF-8 URLs. I am typing the following into the IE8 address bar when debugging the code:</p> <pre> http://app/myHandler.ashx?term=foo // everything works http://app/myHandler.ashx?term=þorn // does not work -- query from database fails </pre> <p>The database is SQLite and it is using UTF-8 encoding and it works fine. The queries that use these special characters work fine when issued directly against SQLite using other GUI tools or using the System.Data.SQLite GUI add-ins to Visual Studio.</p> <p><strong>Am I decoding the values from the Query String correctly? Does GetString() not decode the bytes?</strong></p> <pre> public StandardRequest(HttpContext context) { UTF8Encoding utf8 = new UTF8Encoding(); if (context.Request.QueryString["term"] != null) { byte[] w = utf8.GetBytes(context.Request.QueryString["term"]); word = utf8.GetString(w); ... </pre> <p>In the HTTP handler, ContentEncoding is set to UTF-8:</p> <pre> context.Response.ContentEncoding = System.Text.Encoding.UTF8;</pre> <p>and in the debugger's local's window, Request.ContentEncoding is also UTF-8.</p> <p>But when I examine the query string value in the locals window, the <strong>term</strong> value from the query string <em>'þorn'</em> is being displayed as <em>'[]orn'</em> and that is how it is displayed in the sql statement that I'm sending through to the database. It's as if the character hasn't been recognized.</p> <p>Am I doing something wrong in the way the value is being grabbed from the query string and converted to a string?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload