{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/1706","repository_url":"https://api.github.com/repos/angular-ui/ui-router","labels_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1706/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1706/comments","events_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1706/events","html_url":"https://github.com/angular-ui/ui-router/issues/1706","id":55303627,"number":1706,"title":"Repeated search parameters introduce unwanted polymorphism","user":{"login":"schmod","id":1102667,"avatar_url":"https://avatars.githubusercontent.com/u/1102667?v=3","gravatar_id":"","url":"https://api.github.com/users/schmod","html_url":"https://github.com/schmod","followers_url":"https://api.github.com/users/schmod/followers","following_url":"https://api.github.com/users/schmod/following{/other_user}","gists_url":"https://api.github.com/users/schmod/gists{/gist_id}","starred_url":"https://api.github.com/users/schmod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schmod/subscriptions","organizations_url":"https://api.github.com/users/schmod/orgs","repos_url":"https://api.github.com/users/schmod/repos","events_url":"https://api.github.com/users/schmod/events{/privacy}","received_events_url":"https://api.github.com/users/schmod/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular-ui/ui-router/labels/design","name":"design","color":"009800"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2015-01-23T16:45:32Z","updated_at":"2016-09-21T17:05:06Z","closed_at":"2015-10-23T20:03:22Z","body":"Right now, if I want to pass multiple values into a search parameter, UI-router simply repeats the search parameter for every value that I pass in.  \r\n\r\nFor example:\r\n```js\r\nnew UrlMatcher('/users?{id:int}').format({ id:[1,2] }); // '/users?id=1&id=2`\r\n\r\n// In a state:\r\n$stateParams.id; // [1,2]\r\n```\r\n\r\nHowever, if I only pass in one user ID:\r\n```js\r\nnew UrlMatcher('/users?{id:int}').format({ id:[1] }); // '/users?id=1`\r\n\r\n// In a state:\r\n$stateParams.id; // 1\r\n```\r\n\r\nThis is less-than-ideal, because it makes `$stateParams.id` polymorphic, even when I've specified a typed parameter, and requires a lot of type-checking in controllers.'\r\n\r\nAt the very minimum, I end up with lots of:\r\n```js\r\nvar id = $stateParams.id;\r\nif(!angular.isArray(id)){\r\n  id = [id];\r\n}\r\nid.forEach(...)\r\n```\r\n\r\nWorse still, *any* state parameter risks being cast into an array if a user makes a typo, and specifies the same parameter twice.  This seems likely to cause unpredictable breakages in controllers, given that most developers will not code defensively against this scenario.\r\n\r\nIMO, the search parameter grouping introduced by #373 should require an explicit opt-in for each parameter (*especially* if the parameter is typed).  If the matcher expects multiple values for a parameter, it should *always* deserialize the value(s) into an array, even if only one value is provided.  If the matcher does not expect multiple values, it should return the first one that it finds, and discard subsequent matches (or throw an error).\r\n\r\n---\r\n\r\nSimilarly, I'd also be interested to hear thoughts on introducing support for delimited search/query parameters (eg. `/url?id=1,2`).  While UI-router's current implementation seems to be the most common, [there does not appear to be a standard](http://stackoverflow.com/a/24728298), and delimited lists arguably might produce more readable URLs...\r\n\r\nCertainly not appropriate for all use-cases, but possibly quite useful...\r\n\r\n---\r\n\r\n### Summary\r\n\r\n* Predictability is good.\r\n* Strong typing improves predictability.  It's been an immensely useful addition to ui-router.\r\n* Type-checking is obnoxious, requires lots of boilerplate, and most developers won't do it if they're only expecting a single value.\r\n* If developers *are* expecting multiple values, they shouldn't need to handle a single value as a special case.\r\n* Defining a typed parameter should guarantee that the parameter's value always matches the specified type.\r\n  * For the sake of simplicity and compatibility, the current behavior might be appropriate/acceptable for untyped parameters.  However, it seems inappropriate for typed parameters.  \r\n* Comma-delimited parameters might be cool?"},"comment":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/comments/248677198","html_url":"https://github.com/angular-ui/ui-router/issues/1706#issuecomment-248677198","issue_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1706","id":248677198,"user":{"login":"juliancoleman","id":11545939,"avatar_url":"https://avatars.githubusercontent.com/u/11545939?v=3","gravatar_id":"","url":"https://api.github.com/users/juliancoleman","html_url":"https://github.com/juliancoleman","followers_url":"https://api.github.com/users/juliancoleman/followers","following_url":"https://api.github.com/users/juliancoleman/following{/other_user}","gists_url":"https://api.github.com/users/juliancoleman/gists{/gist_id}","starred_url":"https://api.github.com/users/juliancoleman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliancoleman/subscriptions","organizations_url":"https://api.github.com/users/juliancoleman/orgs","repos_url":"https://api.github.com/users/juliancoleman/repos","events_url":"https://api.github.com/users/juliancoleman/events{/privacy}","received_events_url":"https://api.github.com/users/juliancoleman/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T17:05:05Z","updated_at":"2016-09-21T17:05:05Z","body":"what happens if you need the `$stateParams` to hold something of the nature of `[[\"index\", 10], [\"offset\", 0]]`"}}
{"actor":{"display_login":"juliancoleman"}}