Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous URLs generated for states with optional parameters. #1487

Closed
christopherthielen opened this issue Oct 27, 2014 · 1 comment
Closed
Assignees
Milestone

Comments

@christopherthielen
Copy link
Contributor

Default parameter values are currently squashed using replace("//", with "/"). Consider how this could be enhanced to guarantee url-to-state-to-url mapping.

@christopherthielen christopherthielen self-assigned this Oct 27, 2014
@christopherthielen christopherthielen added this to the 0.2.12 milestone Oct 27, 2014
@christopherthielen
Copy link
Contributor Author

Say a state has 3 optional params, fooid, barid, bazid in the url.

.state('test', { 
  url: '/:fooid/:barid/:bazid',
  params: { fooid: 123, barid: 456, bazid: 789 }
}

When navigating to that state with all default parameters, the url generated is /. When refreshing the browser, the router will match the 'test' state and apply the default params. So-far-so-good. However, if you navigate to 'test' with the second or third parameter set, the href generated is ambiguous. $state.go('test', { bazid: 10000 }) generates a url of /10000. It's impossible to determine what param the 10000 value references. (It will be incorrectly matched to fooid in 0.2.11).

Another use case:

.state('parent', { 
  url: '/parent/:parentid',
  params: { parentid: 'foo' }
})
.state('parent.child', {
  url: '/child
});

The url /parent/bar/child correctly maps to parent.child with parentid set to bar. However, we can generate ambiguous URLs between the two states.

$state.go("parent.child") generates /parent/child due to the optional value rules.
$state.go("parent", { parentid: 'child' }) also generates /parent/child.


The user must be wary of the URLs possibly generated by their state definitions and default values.

We should not allow them to shoot themselves in the foot by default.

@christopherthielen christopherthielen changed the title URL default-parameter-value squashing Ambiguous URLs generated for states with optional parameters. Oct 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant