{"action":"created","issue":{"url":"https://api.github.com/repos/omichelsen/express-ab/issues/15","repository_url":"https://api.github.com/repos/omichelsen/express-ab","labels_url":"https://api.github.com/repos/omichelsen/express-ab/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/omichelsen/express-ab/issues/15/comments","events_url":"https://api.github.com/repos/omichelsen/express-ab/issues/15/events","html_url":"https://github.com/omichelsen/express-ab/issues/15","id":220013080,"number":15,"title":"Directly parsing the cookie content as JSON can throw an error if the content is malformed","user":{"login":"guilhermehn","id":685012,"avatar_url":"https://avatars2.githubusercontent.com/u/685012?v=3","gravatar_id":"","url":"https://api.github.com/users/guilhermehn","html_url":"https://github.com/guilhermehn","followers_url":"https://api.github.com/users/guilhermehn/followers","following_url":"https://api.github.com/users/guilhermehn/following{/other_user}","gists_url":"https://api.github.com/users/guilhermehn/gists{/gist_id}","starred_url":"https://api.github.com/users/guilhermehn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guilhermehn/subscriptions","organizations_url":"https://api.github.com/users/guilhermehn/orgs","repos_url":"https://api.github.com/users/guilhermehn/repos","events_url":"https://api.github.com/users/guilhermehn/events{/privacy}","received_events_url":"https://api.github.com/users/guilhermehn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-06T19:52:37Z","updated_at":"2017-04-06T19:58:16Z","closed_at":null,"body":"I'm heaving trouble with a malformed cookie. The actual content of the cookie is this:\r\n\r\n`%7B%22ps-website-switching%22%3A%22ps-website%22`\r\n\r\nWhich translates to: \r\n\r\n`{\"ps-website-switching\":\"ps-website\"`\r\n\r\nIt's missing the closing bracket, which gives this error stack:\r\n\r\n```\r\ndefaultSyntaxError: Unexpected token / in JSON at position 0 SyntaxError: Unexpected token / in JSON at position 0\r\n   at Object.parse (native)\r\n   at getCookie (/usr/src/app/node_modules/express-ab/lib/express-ab.js:23:25)\r\n   at /usr/src/app/node_modules/express-ab/lib/express-ab.js:52:26\r\n   at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)\r\n   at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:317:13)\r\n   at /usr/src/app/node_modules/express/lib/router/index.js:284:7\r\n   at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:335:12)\r\n   at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)\r\n   at cookieParser (/usr/src/app/node_modules/cookie-parser/index.js:70:5)\r\n   at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)\r\n```\r\n\r\nI think this can be solved quite easily just by wrapping the [`JSON.parse`](https://github.com/omichelsen/express-ab/blob/4ac6f7aa44f4f8dffadca3b0470a24cd2e9571d1/lib/express-ab.js#L23) call in a `try catch` block."},"comment":{"url":"https://api.github.com/repos/omichelsen/express-ab/issues/comments/292297627","html_url":"https://github.com/omichelsen/express-ab/issues/15#issuecomment-292297627","issue_url":"https://api.github.com/repos/omichelsen/express-ab/issues/15","id":292297627,"user":{"login":"omichelsen","id":876633,"avatar_url":"https://avatars2.githubusercontent.com/u/876633?v=3","gravatar_id":"","url":"https://api.github.com/users/omichelsen","html_url":"https://github.com/omichelsen","followers_url":"https://api.github.com/users/omichelsen/followers","following_url":"https://api.github.com/users/omichelsen/following{/other_user}","gists_url":"https://api.github.com/users/omichelsen/gists{/gist_id}","starred_url":"https://api.github.com/users/omichelsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omichelsen/subscriptions","organizations_url":"https://api.github.com/users/omichelsen/orgs","repos_url":"https://api.github.com/users/omichelsen/repos","events_url":"https://api.github.com/users/omichelsen/events{/privacy}","received_events_url":"https://api.github.com/users/omichelsen/received_events","type":"User","site_admin":false},"created_at":"2017-04-06T19:58:16Z","updated_at":"2017-04-06T19:58:16Z","body":"Yeah the lib shouldn't fail if given a bad cookie. Will add that."}}
{"actor":{"display_login":"omichelsen"}}