{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/5961","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5961/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5961/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5961/events","html_url":"https://github.com/crystal-lang/crystal/issues/5961","id":315615291,"number":5961,"title":"\"UT8\" encoding error","user":{"login":"Proximyst","id":19861299,"avatar_url":"https://avatars2.githubusercontent.com/u/19861299?v=4","gravatar_id":"","url":"https://api.github.com/users/Proximyst","html_url":"https://github.com/Proximyst","followers_url":"https://api.github.com/users/Proximyst/followers","following_url":"https://api.github.com/users/Proximyst/following{/other_user}","gists_url":"https://api.github.com/users/Proximyst/gists{/gist_id}","starred_url":"https://api.github.com/users/Proximyst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Proximyst/subscriptions","organizations_url":"https://api.github.com/users/Proximyst/orgs","repos_url":"https://api.github.com/users/Proximyst/repos","events_url":"https://api.github.com/users/Proximyst/events{/privacy}","received_events_url":"https://api.github.com/users/Proximyst/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-18T19:39:55Z","updated_at":"2018-04-18T20:12:44Z","closed_at":null,"author_association":"NONE","body":"As I was improving my spec code to actually use `spec` in the stdlib, I came across quite a weird bug, which happened in all of my specs on the same lines. This is one of the specs:\r\n\r\n```crystal\r\nrequire \"./helper\"\r\n\r\nmodule OwO\r\n  describe WhatsThis do # error: Invalid encoding: ut8\r\n    it \"Upload test image (image.png in root of the repo)\" do\r\n      image_id = inst.upload UploadData.new File.new \"image.png\"\r\n      image_id.nil?.should eq false\r\n      next if !check_file_data\r\n      response = HTTP::Client.get \"https://owo.whats-th.is/#{image_id}\"\r\n      response.status_code.should eq 200\r\n      response.body.should eq File.read \"image.png\"\r\n    end\r\n  end\r\nend\r\n```\r\nI got suspicious, and tried this instead:\r\n```crystal\r\nmodule OwO\r\n  class Test\r\n  end\r\n  describe Test do\r\n    it \"lol\" do\r\n      true.should eq true\r\n    end\r\n  end\r\nend\r\n```\r\nThis worked splendidly, but nowhere in my code is `ut8` ever mentioned, nor is it in Cossack (at least using `grep` recursively with `ut8`, `Ut8`, `uT8` and `UT8`) which I use for my library. The full stack trace is as follows:\r\n```\r\n  1) OwO::WhatsThis Upload test image (image.png in root of the repo)\r\n\r\n       Invalid encoding: ut8\r\n       /usr/lib/crystal/iconv.cr:27:35 in 'initialize'\r\n       /usr/lib/crystal/iconv.cr:7:3 in 'new'\r\n       /usr/lib/crystal/io/encoding.cr:59:16 in 'initialize'\r\n       /usr/lib/crystal/io/encoding.cr:58:5 in 'new'\r\n       /usr/lib/crystal/io.cr:502:7 in 'decoder'\r\n       /usr/lib/crystal/io.cr:551:10 in 'gets_to_end'\r\n       /usr/lib/crystal/http/client/response.cr:73:15 in 'consume_body_io'\r\n       /usr/lib/crystal/http/client/response.cr:97:9 in 'from_io?'\r\n       /usr/lib/crystal/http/client.cr:502:5 in 'exec_internal_single'\r\n       /usr/lib/crystal/http/client.cr:486:5 in 'exec_internal'\r\n       /usr/lib/crystal/http/client.cr:482:5 in 'exec'\r\n       /usr/lib/crystal/http/client.cr:585:5 in 'exec'\r\n       /usr/lib/crystal/http/client.cr:612:7 in 'exec'\r\n       /usr/lib/crystal/http/client.cr:329:3 in 'get'\r\n       /usr/lib/crystal/spec/methods.cr:16:5 in '~procProc(Nil)'\r\n       /usr/lib/crystal/spec/methods.cr:255:3 in 'it'\r\n       /usr/lib/crystal/spec/methods.cr:16:5 in '~procProc(Nil)'\r\n       /usr/lib/crystal/spec/context.cr:255:3 in 'describe'\r\n       /usr/lib/crystal/spec/methods.cr:16:5 in 'describe'\r\n       spec/image_spec.cr:4:3 in '__crystal_main'\r\n       /usr/lib/crystal/crystal/main.cr:11:3 in '_crystal_main'\r\n       /usr/lib/crystal/crystal/main.cr:112:5 in 'main_user_code'\r\n       /usr/lib/crystal/crystal/main.cr:101:7 in 'main'\r\n       /usr/lib/crystal/crystal/main.cr:135:3 in 'main'\r\n       __libc_start_main\r\n       _start\r\n       ???\r\n```\r\nI quite simply am unable to find out what this comes of, and I suspect it's in the Crystal source somewhere.."},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/382514099","html_url":"https://github.com/crystal-lang/crystal/issues/5961#issuecomment-382514099","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5961","id":382514099,"user":{"login":"straight-shoota","id":466378,"avatar_url":"https://avatars0.githubusercontent.com/u/466378?v=4","gravatar_id":"","url":"https://api.github.com/users/straight-shoota","html_url":"https://github.com/straight-shoota","followers_url":"https://api.github.com/users/straight-shoota/followers","following_url":"https://api.github.com/users/straight-shoota/following{/other_user}","gists_url":"https://api.github.com/users/straight-shoota/gists{/gist_id}","starred_url":"https://api.github.com/users/straight-shoota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/straight-shoota/subscriptions","organizations_url":"https://api.github.com/users/straight-shoota/orgs","repos_url":"https://api.github.com/users/straight-shoota/repos","events_url":"https://api.github.com/users/straight-shoota/events{/privacy}","received_events_url":"https://api.github.com/users/straight-shoota/received_events","type":"User","site_admin":false},"created_at":"2018-04-18T20:12:43Z","updated_at":"2018-04-18T20:12:43Z","author_association":"CONTRIBUTOR","body":"This issue has nothing to do with running as spec. You could easily reduce this to a minimal example which would be `HTTP::Client.get \"https://owo.whats-th.is/#{image_id}\"` (where `image_id` is a valid ID). As I can't access your service and I don't know what it does, I can only assume.\r\n\r\n`HTTP::Client.get` consumes the body of the HTTP request and reads it into a `String` as `response.body`. I suspect that the body is actually binary data or at least not UTF-8 encoded. That's why iconv errors out when it finds a byte sequence that is not a valid UTF-8 codepoint.\r\n\r\nIf this is a bug I don't know. Can't tell without knowing the actual HTTP response.\r\n\r\nBut you should probably use `HTTP::Client.get` with a block, which yields the response and shouldn't consume the body. But you can use `response.body_io` to access it as an IO."}}
{"actor":{"display_login":"straight-shoota"}}