{"action":"created","issue":{"url":"https://api.github.com/repos/jhthorsen/mojolicious-plugin-cgi/issues/23","repository_url":"https://api.github.com/repos/jhthorsen/mojolicious-plugin-cgi","labels_url":"https://api.github.com/repos/jhthorsen/mojolicious-plugin-cgi/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/jhthorsen/mojolicious-plugin-cgi/issues/23/comments","events_url":"https://api.github.com/repos/jhthorsen/mojolicious-plugin-cgi/issues/23/events","html_url":"https://github.com/jhthorsen/mojolicious-plugin-cgi/issues/23","id":176237834,"number":23,"title":"Encoding of path_info is dubious","user":{"login":"kensanata","id":1145712,"avatar_url":"https://avatars.githubusercontent.com/u/1145712?v=3","gravatar_id":"","url":"https://api.github.com/users/kensanata","html_url":"https://github.com/kensanata","followers_url":"https://api.github.com/users/kensanata/followers","following_url":"https://api.github.com/users/kensanata/following{/other_user}","gists_url":"https://api.github.com/users/kensanata/gists{/gist_id}","starred_url":"https://api.github.com/users/kensanata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kensanata/subscriptions","organizations_url":"https://api.github.com/users/kensanata/orgs","repos_url":"https://api.github.com/users/kensanata/repos","events_url":"https://api.github.com/users/kensanata/events{/privacy}","received_events_url":"https://api.github.com/users/kensanata/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-11T10:43:43Z","updated_at":"2016-09-11T11:03:33Z","closed_at":null,"body":"I've noticed a problem with `PATH_INFO` if it contains non-ASCII characters. Here's how to reproduce it.\r\n\r\n```\r\n#!/usr/bin/env perl\r\nuse Mojolicious::Lite;\r\nuse Encode qw(decode_utf8);\r\n\r\nplugin CGI => {\r\n  route => '/',\r\n  run => sub {\r\n    print \"HTTP/1.1 200 OK\\r\\n\";\r\n    print \"Content-Type: text/html; charset=UTF-8\\r\\n\";\r\n    print \"\\r\\n\";\r\n    my $path_info = decode_utf8($ENV{PATH_INFO});\r\n    my $query_string = $ENV{QUERY_STRING};\r\n    $query_string =~ s/%([0-9a-f][0-9a-f])/chr(hex($1))/egi;\r\n    $query_string = decode_utf8($query_string);\r\n    binmode(STDOUT, \":encoding(UTF-8)\");\r\n    print \"<body>\";\r\n    print \"<p>Path Info: $path_info\";\r\n    print \"<br>Query String: $query_string\";\r\n  },\r\n};\r\n\r\napp->start;\r\n```\r\n\r\nRun it using `perl something.pl daemon` and visit the following URL:\r\nhttp://127.0.0.1:3000/f%C3%B6%C3%B6%E2%80%99s?g%C3%B6%C3%B6%E2%80%99s\r\n\r\nWe get a warning (**Wide character in setenv**) but the result is correct:\r\n```\r\nPath Info: /föö’s\r\nQuery String: göö’s\r\n```\r\n\r\nNow visit this URL:\r\nhttp://127.0.0.1:3000/f%C3%B6%C3%B6?g%C3%B6%C3%B6\r\n\r\nWe get no warning but the `PATH_INFO` result is corrupted:\r\n```\r\nPath Info: /f��\r\nQuery String: göö\r\n```\r\n\r\nI am reminded of this sentence in the `Encode` man page: «When you decode, the Unicode REPLACEMENT CHARACTER, code point U+FFFD, is used.» The setenv warning is another hint. But first, let's make sure that Mojolicious is not at fault. If you use just `Mojolicious::Lite`, there is no problem. Use the same two URLs as above and the following app. There appear to be no problems.\r\n\r\n```\r\n#!/usr/bin/env perl\r\nuse Mojolicious::Lite;\r\n\r\nget '/*path_info' => sub {\r\n  my $c = shift;\r\n  $c->render(text => \"Path Info: \" . $c->stash('path_info'));\r\n};\r\n\r\napp->start;\r\n```\r\n\r\nI'll try and submit a pull request in a bit."},"comment":{"url":"https://api.github.com/repos/jhthorsen/mojolicious-plugin-cgi/issues/comments/246174552","html_url":"https://github.com/jhthorsen/mojolicious-plugin-cgi/issues/23#issuecomment-246174552","issue_url":"https://api.github.com/repos/jhthorsen/mojolicious-plugin-cgi/issues/23","id":246174552,"user":{"login":"kensanata","id":1145712,"avatar_url":"https://avatars.githubusercontent.com/u/1145712?v=3","gravatar_id":"","url":"https://api.github.com/users/kensanata","html_url":"https://github.com/kensanata","followers_url":"https://api.github.com/users/kensanata/followers","following_url":"https://api.github.com/users/kensanata/following{/other_user}","gists_url":"https://api.github.com/users/kensanata/gists{/gist_id}","starred_url":"https://api.github.com/users/kensanata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kensanata/subscriptions","organizations_url":"https://api.github.com/users/kensanata/orgs","repos_url":"https://api.github.com/users/kensanata/repos","events_url":"https://api.github.com/users/kensanata/events{/privacy}","received_events_url":"https://api.github.com/users/kensanata/received_events","type":"User","site_admin":false},"created_at":"2016-09-11T11:03:33Z","updated_at":"2016-09-11T11:03:33Z","body":"Sadly, I was able to write a test that triggers the warning, but I was unable to write a test that's fatal. I'll give this some more thought."}}
{"actor":{"display_login":"kensanata"}}