You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Trailing ? in url when setting query_values to an empty hash #5
describe "#query_values=" do
context "when passed an empty Hash" do
it "should result in the query section being removed" do
uri = Addressable.parse("http://example.com/?login=true")
uri.query_values = {}
uri.to_s.should == "http://example.com/"
end
end
end
After careful consideration, I've decided that this is not desirable behavior. If you do not want a trailing ? character, set Addressable::URI#query_values or Addressable::URI#query to nil.
I am not sure where the question mark came from, but this happens in my tests. I am expecting calling normalize! should remove the question mark.
Thanks!
No, in this case, that is doing the correct thing. Those are distinctly different URIs, believe it or not. In fact, in my original reply to this issue, you can see that I made sure to draw the distinction between the nil query and the empty query.
I think it might be reasonable to introduce a #normalize_form_encoded_query method that would handle this (and a number of other similar issues), but unless you can make the assumption that your query is form-encoded, you cannot strip the trailing ? character.
Activity
sporkmonger commentedon Jul 14, 2010
After careful consideration, I've decided that this is not desirable behavior. If you do not want a trailing
?character, setAddressable::URI#query_valuesorAddressable::URI#queryto nil.sporkmonger commentedon Jul 14, 2010
A nil may now be passed to Addressable::URI#query_values=. Closed by 940f432.
godfat commentedon Oct 20, 2010
Sorry, but what about this?
Addressable::URI.parse('http://example.com?').normalize!.to_s == 'http://example.com'I am not sure where the question mark came from, but this happens in my tests. I am expecting calling normalize! should remove the question mark.
Thanks!
sporkmonger commentedon Oct 20, 2010
No, in this case, that is doing the correct thing. Those are distinctly different URIs, believe it or not. In fact, in my original reply to this issue, you can see that I made sure to draw the distinction between the
nilquery and the empty query.I think it might be reasonable to introduce a
#normalize_form_encoded_querymethod that would handle this (and a number of other similar issues), but unless you can make the assumption that your query is form-encoded, you cannot strip the trailing?character.godfat commentedon Oct 20, 2010
Thanks for the explanation and the great library :)