Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

How to handle missing parameters #3

Open
moonglum opened this issue Dec 22, 2015 · 2 comments
Open

How to handle missing parameters #3

moonglum opened this issue Dec 22, 2015 · 2 comments

Comments

@moonglum
Copy link
Owner

What if a parameter is not provided? In the RFC it is handled like this:

A variable that is undefined (Section 2.3) has no value and is ignored by the expansion process. If all of the variables in an expression are undefined, then the expression's expansion is the empty string.

I don’t think that makes a lot of sense for this use case here, as broken URLs can arise. It probably should be handled differently for different kinds of parameters, maybe like this:

test 'route with a missing regular parameter' do |routes|
  routes.define :users, '/users/{id}'
  assert_raise(ArgumentError) { routes.uri_for(:users) }
end

test 'route with a missing query parameter' do |routes|
  routes.define :users, '/users{?name,country}'
  assert_equal '/users?name=alice', routes.uri_for(:users, name: 'alice')
end

test 'route with a missing path parameter' do |routes|
  routes.define :users, '/users{/x,y}'
  assert_raise(ArgumentError) { routes.uri_for(:users, x: 'alice') }
end
@soveran
Copy link

soveran commented Dec 22, 2015

I don’t think that makes a lot of sense for this use case here, as broken URLs can arise.

I agree with you: for anything that helps build the path (first and third tests in your example), an error should be raised. What is mentioned in the RFC should only apply to the second test, but in any case we can keep an eye on this to see what's the most common expectation based on our use cases.

@moonglum
Copy link
Owner Author

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants