{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/26841","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/26841/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/26841/comments","events_url":"https://api.github.com/repos/rails/rails/issues/26841/events","html_url":"https://github.com/rails/rails/pull/26841","id":184201089,"number":26841,"title":"Be able to use String#blank? with invalid encoding","user":{"login":"purintai","id":881478,"avatar_url":"https://avatars.githubusercontent.com/u/881478?v=3","gravatar_id":"","url":"https://api.github.com/users/purintai","html_url":"https://github.com/purintai","followers_url":"https://api.github.com/users/purintai/followers","following_url":"https://api.github.com/users/purintai/following{/other_user}","gists_url":"https://api.github.com/users/purintai/gists{/gist_id}","starred_url":"https://api.github.com/users/purintai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purintai/subscriptions","organizations_url":"https://api.github.com/users/purintai/orgs","repos_url":"https://api.github.com/users/purintai/repos","events_url":"https://api.github.com/users/purintai/events{/privacy}","received_events_url":"https://api.github.com/users/purintai/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/activesupport","name":"activesupport","color":"FC9300"}],"state":"open","locked":false,"assignee":{"login":"schneems","id":59744,"avatar_url":"https://avatars.githubusercontent.com/u/59744?v=3","gravatar_id":"","url":"https://api.github.com/users/schneems","html_url":"https://github.com/schneems","followers_url":"https://api.github.com/users/schneems/followers","following_url":"https://api.github.com/users/schneems/following{/other_user}","gists_url":"https://api.github.com/users/schneems/gists{/gist_id}","starred_url":"https://api.github.com/users/schneems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schneems/subscriptions","organizations_url":"https://api.github.com/users/schneems/orgs","repos_url":"https://api.github.com/users/schneems/repos","events_url":"https://api.github.com/users/schneems/events{/privacy}","received_events_url":"https://api.github.com/users/schneems/received_events","type":"User","site_admin":false},"assignees":[{"login":"schneems","id":59744,"avatar_url":"https://avatars.githubusercontent.com/u/59744?v=3","gravatar_id":"","url":"https://api.github.com/users/schneems","html_url":"https://github.com/schneems","followers_url":"https://api.github.com/users/schneems/followers","following_url":"https://api.github.com/users/schneems/following{/other_user}","gists_url":"https://api.github.com/users/schneems/gists{/gist_id}","starred_url":"https://api.github.com/users/schneems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schneems/subscriptions","organizations_url":"https://api.github.com/users/schneems/orgs","repos_url":"https://api.github.com/users/schneems/repos","events_url":"https://api.github.com/users/schneems/events{/privacy}","received_events_url":"https://api.github.com/users/schneems/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2016-10-20T11:14:10Z","updated_at":"2016-10-20T15:49:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/26841","html_url":"https://github.com/rails/rails/pull/26841","diff_url":"https://github.com/rails/rails/pull/26841.diff","patch_url":"https://github.com/rails/rails/pull/26841.patch"},"body":"### Summary\r\n\r\nShould be able to call `String#blank?` against invalid encoding String object.\r\n\r\n`Regexp.match` will raise `ArgumentError` if passed invalid encoding strings.\r\nI thought if the string including invalid encoding characters, it is not blank.\r\n\r\nThis change to be effective in the below case.\r\n\r\n```ruby\r\n\r\nrow = {\r\n  \"name\"  => \"Cardinal Slant-D\\xAE Ring Binder\",\r\n  \"price\" => \"2930\",\r\n  \"include_tax\" => \"\",\r\n  \"ship-weight\" => \"420.80\",\r\n  \"category-name\" => \"Office Furnishings\",\r\n  \"manufacturer\" => \"\",\r\n}\r\n\r\nparams = Hash[row.map{|k, v| [k.tr('-', '_'), v.presence&.scrub]}].compact\r\nProduct.create(params)\r\n```"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/255146265","html_url":"https://github.com/rails/rails/pull/26841#issuecomment-255146265","issue_url":"https://api.github.com/repos/rails/rails/issues/26841","id":255146265,"user":{"login":"schneems","id":59744,"avatar_url":"https://avatars.githubusercontent.com/u/59744?v=3","gravatar_id":"","url":"https://api.github.com/users/schneems","html_url":"https://github.com/schneems","followers_url":"https://api.github.com/users/schneems/followers","following_url":"https://api.github.com/users/schneems/following{/other_user}","gists_url":"https://api.github.com/users/schneems/gists{/gist_id}","starred_url":"https://api.github.com/users/schneems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schneems/subscriptions","organizations_url":"https://api.github.com/users/schneems/orgs","repos_url":"https://api.github.com/users/schneems/repos","events_url":"https://api.github.com/users/schneems/events{/privacy}","received_events_url":"https://api.github.com/users/schneems/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T15:49:54Z","updated_at":"2016-10-20T15:49:54Z","body":"Was worried about speed, but it looks not too bad\r\n\r\n```\r\nrequire 'benchmark/ips'\r\n\r\nBLANK_RE = /\\A[[:space:]]*\\z/\r\n\r\ndef current(string)\r\n  BLANK_RE.match?(string)\r\nend\r\n\r\ndef proposed(string)\r\n  string.valid_encoding? && BLANK_RE.match?(string)\r\nend\r\n\r\n\r\nvalid_string = \"i am a valid non empty string\".freeze\r\n\r\nBenchmark.ips do |x|\r\n  x.report(\"current\") {|times|\r\n    i = 0\r\n    while i < times\r\n      i += 1\r\n      current(valid_string)\r\n    end\r\n  }\r\n  x.report(\"proposed\") {|times|\r\n    i = 0\r\n    while i < times\r\n      i += 1\r\n      proposed(valid_string)\r\n    end\r\n  }\r\n  x.compare!\r\nend\r\n# Warming up --------------------------------------\r\n#              current   174.871k i/100ms\r\n#             proposed   159.532k i/100ms\r\n# Calculating -------------------------------------\r\n#              current      5.442M (± 9.9%) i/s -     27.105M in   5.029241s\r\n#             proposed      4.635M (±10.8%) i/s -     22.973M in   5.026252s\r\n\r\n# Comparison:\r\n#              current:  5442135.3 i/s\r\n#             proposed:  4634679.5 i/s - same-ish: difference falls within error\r\n```\r\n\r\ncc @fxn @SamSaffron"}}
{"actor":{"display_login":"schneems"}}