Skip to content

Commit

Permalink
Don't print query params if they are empty (#5340)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcsmith authored and bcardiff committed Dec 3, 2017
1 parent e482297 commit b747f5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 14 additions & 6 deletions spec/std/uri_spec.cr
Expand Up @@ -32,12 +32,20 @@ describe "URI" do
assert_uri("/foo?q=1", path: "/foo", query: "q=1")
assert_uri("mailto:foo@example.org", scheme: "mailto", path: nil, opaque: "foo@example.org")

it { URI.parse("http://www.example.com/foo").full_path.should eq("/foo") }
it { URI.parse("http://www.example.com").full_path.should eq("/") }
it { URI.parse("http://www.example.com/foo?q=1").full_path.should eq("/foo?q=1") }
it { URI.parse("http://www.example.com/?q=1").full_path.should eq("/?q=1") }
it { URI.parse("http://www.example.com?q=1").full_path.should eq("/?q=1") }
it { URI.parse("http://test.dev/a%3Ab").full_path.should eq("/a%3Ab") }
describe "full_path" do
it { URI.parse("http://www.example.com/foo").full_path.should eq("/foo") }
it { URI.parse("http://www.example.com").full_path.should eq("/") }
it { URI.parse("http://www.example.com/foo?q=1").full_path.should eq("/foo?q=1") }
it { URI.parse("http://www.example.com/?q=1").full_path.should eq("/?q=1") }
it { URI.parse("http://www.example.com?q=1").full_path.should eq("/?q=1") }
it { URI.parse("http://test.dev/a%3Ab").full_path.should eq("/a%3Ab") }

it "does not add '?' to the end if the query params are empty" do
uri = URI.parse("http://www.example.com/foo")
uri.query = ""
uri.full_path.should eq("/foo")
end
end

describe "normalize" do
it "removes dot notation from path" do
Expand Down
4 changes: 3 additions & 1 deletion src/uri.cr
Expand Up @@ -128,7 +128,9 @@ class URI
def full_path
String.build do |str|
str << (@path.try { |p| !p.empty? } ? @path : "/")
str << "?" << @query if @query
if (query = @query) && !query.empty?
str << "?" << query
end
end
end

Expand Down

0 comments on commit b747f5f

Please sign in to comment.