Skip to content

Trailing ? in url when setting query_values to an empty hash #5

Closed

Description

@honkster
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

Activity

  1. sporkmonger commented on Jul 14, 2010

    @sporkmonger
    Owner

    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.

  2. sporkmonger commented on Jul 14, 2010

    @sporkmonger
    Owner

    A nil may now be passed to Addressable::URI#query_values=. Closed by 940f432.

  3. godfat commented on Oct 20, 2010

    @godfat

    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!

  4. sporkmonger commented on Oct 20, 2010

    @sporkmonger
    Owner

    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.

  5. godfat commented on Oct 20, 2010

    @godfat

    Thanks for the explanation and the great library :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions