{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/imminence/pulls/comments/43644895","id":43644895,"diff_hunk":"@@ -18,7 +18,11 @@ def index\n   end\n \n   def search\n-    api_response = Imminence.mapit_api.location_for_postcode(params[:postcode])\n+    # Strip trailing whitespace, most non-alphanumerics, and use the\n+    # uk_postcode gem to potentially transpose O/0 and I/1.\n+    sanitized_postcode = UKPostcode.parse(params[:postcode].gsub(/[^\\w\\s]/i, '').strip).to_s","path":"app/controllers/areas_controller.rb","position":null,"original_position":7,"commit_id":"ec6d27e1da526d3c0e5a55129bfe1eae2cb2bc0b","original_commit_id":"fa6e1ac9d451e401529bdecd33baf278f85305c4","user":{"login":"issyl0","id":355033,"avatar_url":"https://avatars.githubusercontent.com/u/355033?v=3","gravatar_id":"","url":"https://api.github.com/users/issyl0","html_url":"https://github.com/issyl0","followers_url":"https://api.github.com/users/issyl0/followers","following_url":"https://api.github.com/users/issyl0/following{/other_user}","gists_url":"https://api.github.com/users/issyl0/gists{/gist_id}","starred_url":"https://api.github.com/users/issyl0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/issyl0/subscriptions","organizations_url":"https://api.github.com/users/issyl0/orgs","repos_url":"https://api.github.com/users/issyl0/repos","events_url":"https://api.github.com/users/issyl0/events{/privacy}","received_events_url":"https://api.github.com/users/issyl0/received_events","type":"User","site_admin":false},"body":"I've made it into a `PostcodeSanitizer` class with a `sanitize` method that takes the postcode, and written tests for each of the different things it does. Thanks!","created_at":"2015-11-02T16:09:08Z","updated_at":"2015-11-02T16:09:08Z","html_url":"https://github.com/alphagov/imminence/pull/116#discussion_r43644895","pull_request_url":"https://api.github.com/repos/alphagov/imminence/pulls/116","_links":{"self":{"href":"https://api.github.com/repos/alphagov/imminence/pulls/comments/43644895"},"html":{"href":"https://github.com/alphagov/imminence/pull/116#discussion_r43644895"},"pull_request":{"href":"https://api.github.com/repos/alphagov/imminence/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/imminence/pulls/116","id":49427692,"html_url":"https://github.com/alphagov/imminence/pull/116","diff_url":"https://github.com/alphagov/imminence/pull/116.diff","patch_url":"https://github.com/alphagov/imminence/pull/116.patch","issue_url":"https://api.github.com/repos/alphagov/imminence/issues/116","number":116,"state":"open","locked":false,"title":"Autocorrect mistakes in postcodes entered into local transaction pages","user":{"login":"issyl0","id":355033,"avatar_url":"https://avatars.githubusercontent.com/u/355033?v=3","gravatar_id":"","url":"https://api.github.com/users/issyl0","html_url":"https://github.com/issyl0","followers_url":"https://api.github.com/users/issyl0/followers","following_url":"https://api.github.com/users/issyl0/following{/other_user}","gists_url":"https://api.github.com/users/issyl0/gists{/gist_id}","starred_url":"https://api.github.com/users/issyl0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/issyl0/subscriptions","organizations_url":"https://api.github.com/users/issyl0/orgs","repos_url":"https://api.github.com/users/issyl0/repos","events_url":"https://api.github.com/users/issyl0/events{/privacy}","received_events_url":"https://api.github.com/users/issyl0/received_events","type":"User","site_admin":false},"body":"- We were seeing lots of errors for postcodes entered\r\n  with obvious typos, eg. hyphens instead of spaces, 0 instead of O, L\r\n  instead of 1, etc, so this is an attempt at fixing most common ones.\r\n- Strip most non-alphanumerics and trailing whitespace. Also use the\r\n  `uk_postcode` gem to fix transposition of L/1, O/0.\r\n- The `routes.rb` file had a constraint on the `areas/postcode` route,\r\n  but this change failed to work with it, so I've removed it in favour\r\n  of a better regex in the controller.\r\n\r\nTrello: https://trello.com/c/2KHTEa4l/127-auto-correct-mistakes-in-postcodes-entered-by-users-on-local-transaction-pages.\r\n\r\n(Thanks to @h-lame for help with understanding the tests.)","created_at":"2015-11-02T12:49:49Z","updated_at":"2015-11-02T16:09:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58b52ba17d4b7d5d3f51cc8d480ad55cfcac9e83","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/imminence/pulls/116/commits","review_comments_url":"https://api.github.com/repos/alphagov/imminence/pulls/116/comments","review_comment_url":"https://api.github.com/repos/alphagov/imminence/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/imminence/issues/116/comments","statuses_url":"https://api.github.com/repos/alphagov/imminence/statuses/ec6d27e1da526d3c0e5a55129bfe1eae2cb2bc0b","head":{"label":"alphagov:autocorrect_postcode_typos","ref":"autocorrect_postcode_typos","sha":"ec6d27e1da526d3c0e5a55129bfe1eae2cb2bc0b","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":2147546,"name":"imminence","full_name":"alphagov/imminence","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/imminence","description":"\"Find My Nearest\" API and management tools","fork":false,"url":"https://api.github.com/repos/alphagov/imminence","forks_url":"https://api.github.com/repos/alphagov/imminence/forks","keys_url":"https://api.github.com/repos/alphagov/imminence/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/imminence/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/imminence/teams","hooks_url":"https://api.github.com/repos/alphagov/imminence/hooks","issue_events_url":"https://api.github.com/repos/alphagov/imminence/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/imminence/events","assignees_url":"https://api.github.com/repos/alphagov/imminence/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/imminence/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/imminence/tags","blobs_url":"https://api.github.com/repos/alphagov/imminence/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/imminence/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/imminence/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/imminence/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/imminence/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/imminence/languages","stargazers_url":"https://api.github.com/repos/alphagov/imminence/stargazers","contributors_url":"https://api.github.com/repos/alphagov/imminence/contributors","subscribers_url":"https://api.github.com/repos/alphagov/imminence/subscribers","subscription_url":"https://api.github.com/repos/alphagov/imminence/subscription","commits_url":"https://api.github.com/repos/alphagov/imminence/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/imminence/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/imminence/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/imminence/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/imminence/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/imminence/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/imminence/merges","archive_url":"https://api.github.com/repos/alphagov/imminence/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/imminence/downloads","issues_url":"https://api.github.com/repos/alphagov/imminence/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/imminence/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/imminence/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/imminence/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/imminence/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/imminence/releases{/id}","created_at":"2011-08-03T08:52:34Z","updated_at":"2014-12-10T14:07:32Z","pushed_at":"2015-11-02T16:04:45Z","git_url":"git://github.com/alphagov/imminence.git","ssh_url":"git@github.com:alphagov/imminence.git","clone_url":"https://github.com/alphagov/imminence.git","svn_url":"https://github.com/alphagov/imminence","homepage":"","size":2894,"stargazers_count":6,"watchers_count":6,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":6,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"32b6d7ee06c2a11d549f3e15387af4fb7dfa58ea","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":2147546,"name":"imminence","full_name":"alphagov/imminence","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/imminence","description":"\"Find My Nearest\" API and management tools","fork":false,"url":"https://api.github.com/repos/alphagov/imminence","forks_url":"https://api.github.com/repos/alphagov/imminence/forks","keys_url":"https://api.github.com/repos/alphagov/imminence/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/imminence/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/imminence/teams","hooks_url":"https://api.github.com/repos/alphagov/imminence/hooks","issue_events_url":"https://api.github.com/repos/alphagov/imminence/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/imminence/events","assignees_url":"https://api.github.com/repos/alphagov/imminence/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/imminence/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/imminence/tags","blobs_url":"https://api.github.com/repos/alphagov/imminence/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/imminence/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/imminence/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/imminence/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/imminence/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/imminence/languages","stargazers_url":"https://api.github.com/repos/alphagov/imminence/stargazers","contributors_url":"https://api.github.com/repos/alphagov/imminence/contributors","subscribers_url":"https://api.github.com/repos/alphagov/imminence/subscribers","subscription_url":"https://api.github.com/repos/alphagov/imminence/subscription","commits_url":"https://api.github.com/repos/alphagov/imminence/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/imminence/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/imminence/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/imminence/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/imminence/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/imminence/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/imminence/merges","archive_url":"https://api.github.com/repos/alphagov/imminence/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/imminence/downloads","issues_url":"https://api.github.com/repos/alphagov/imminence/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/imminence/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/imminence/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/imminence/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/imminence/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/imminence/releases{/id}","created_at":"2011-08-03T08:52:34Z","updated_at":"2014-12-10T14:07:32Z","pushed_at":"2015-11-02T16:04:45Z","git_url":"git://github.com/alphagov/imminence.git","ssh_url":"git@github.com:alphagov/imminence.git","clone_url":"https://github.com/alphagov/imminence.git","svn_url":"https://github.com/alphagov/imminence","homepage":"","size":2894,"stargazers_count":6,"watchers_count":6,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/imminence/pulls/116"},"html":{"href":"https://github.com/alphagov/imminence/pull/116"},"issue":{"href":"https://api.github.com/repos/alphagov/imminence/issues/116"},"comments":{"href":"https://api.github.com/repos/alphagov/imminence/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/imminence/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/imminence/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/imminence/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/imminence/statuses/ec6d27e1da526d3c0e5a55129bfe1eae2cb2bc0b"}}}}