{"action":"created","issue":{"url":"https://api.github.com/repos/cheecheeo/haskell-cgi/issues/23","repository_url":"https://api.github.com/repos/cheecheeo/haskell-cgi","labels_url":"https://api.github.com/repos/cheecheeo/haskell-cgi/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/cheecheeo/haskell-cgi/issues/23/comments","events_url":"https://api.github.com/repos/cheecheeo/haskell-cgi/issues/23/events","html_url":"https://github.com/cheecheeo/haskell-cgi/issues/23","id":131832127,"number":23,"title":"issues with Unicode in query string","user":{"login":"ninegua","id":1549364,"avatar_url":"https://avatars.githubusercontent.com/u/1549364?v=3","gravatar_id":"","url":"https://api.github.com/users/ninegua","html_url":"https://github.com/ninegua","followers_url":"https://api.github.com/users/ninegua/followers","following_url":"https://api.github.com/users/ninegua/following{/other_user}","gists_url":"https://api.github.com/users/ninegua/gists{/gist_id}","starred_url":"https://api.github.com/users/ninegua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ninegua/subscriptions","organizations_url":"https://api.github.com/users/ninegua/orgs","repos_url":"https://api.github.com/users/ninegua/repos","events_url":"https://api.github.com/users/ninegua/events{/privacy}","received_events_url":"https://api.github.com/users/ninegua/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-02-06T07:29:30Z","updated_at":"2016-02-17T05:52:12Z","closed_at":null,"body":"~~~\r\n*Main> import Network.CGI\r\n*Main Network.CGI> import Data.ByteString.Char8 as BS\r\n*Main Network.CGI BS> let [(n,v)] = formDecode \"term=%CE%BBx.x\"\r\n*Main Network.CGI BS> BS.pack v\r\n\"\\187x.x\"\r\n*Main Network.CGI BS> v\r\n\"\\955x.x\"\r\n*Main Network.CGI BS> putStrLn v\r\nλx.x\r\n~~~\r\n\r\nThe above shows what is wrong with `BS.pack` [in this line](https://github.com/cheecheeo/haskell-cgi/blob/master/Network/CGI/Protocol.hs#L172): it is not respecting Unicode strings that are decoded from `QUERY_STRING` environment. The consequence is that `getInput` is no longer returning the correct value, and it is impossible to recover the correct value afterwards.\r\n\r\nOlder bytestring package (e.g., bytestring-0.9.2.1) actually was able to pack Unicode into UTF-8 sequences even when you use Char8, but this is no longer the case. I would advise the CGI package either store things internally as String, or use utf8-string package to pack things properly.\r\n"},"comment":{"url":"https://api.github.com/repos/cheecheeo/haskell-cgi/issues/comments/185039949","html_url":"https://github.com/cheecheeo/haskell-cgi/issues/23#issuecomment-185039949","issue_url":"https://api.github.com/repos/cheecheeo/haskell-cgi/issues/23","id":185039949,"user":{"login":"ninegua","id":1549364,"avatar_url":"https://avatars.githubusercontent.com/u/1549364?v=3","gravatar_id":"","url":"https://api.github.com/users/ninegua","html_url":"https://github.com/ninegua","followers_url":"https://api.github.com/users/ninegua/followers","following_url":"https://api.github.com/users/ninegua/following{/other_user}","gists_url":"https://api.github.com/users/ninegua/gists{/gist_id}","starred_url":"https://api.github.com/users/ninegua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ninegua/subscriptions","organizations_url":"https://api.github.com/users/ninegua/orgs","repos_url":"https://api.github.com/users/ninegua/repos","events_url":"https://api.github.com/users/ninegua/events{/privacy}","received_events_url":"https://api.github.com/users/ninegua/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T05:52:12Z","updated_at":"2016-02-17T05:52:12Z","body":"BTW, another solution is to use a ByteString equivalent of getEnvironment, which is provided in recent unix package for Posix systems `System:\r\n\r\nhttps://hackage.haskell.org/package/unix-2.7.1.0/docs/System-Posix-Env-ByteString.html\r\n\r\nUnfortunately this package doesn't support Windows."}}