Skip to content

Commit b747f5f

Browse files
paulcsmithbcardiff
authored andcommittedDec 3, 2017
Don't print query params if they are empty (#5340)
1 parent e482297 commit b747f5f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed
 

‎spec/std/uri_spec.cr

+14-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ describe "URI" do
3232
assert_uri("/foo?q=1", path: "/foo", query: "q=1")
3333
assert_uri("mailto:foo@example.org", scheme: "mailto", path: nil, opaque: "foo@example.org")
3434

35-
it { URI.parse("http://www.example.com/foo").full_path.should eq("/foo") }
36-
it { URI.parse("http://www.example.com").full_path.should eq("/") }
37-
it { URI.parse("http://www.example.com/foo?q=1").full_path.should eq("/foo?q=1") }
38-
it { URI.parse("http://www.example.com/?q=1").full_path.should eq("/?q=1") }
39-
it { URI.parse("http://www.example.com?q=1").full_path.should eq("/?q=1") }
40-
it { URI.parse("http://test.dev/a%3Ab").full_path.should eq("/a%3Ab") }
35+
describe "full_path" do
36+
it { URI.parse("http://www.example.com/foo").full_path.should eq("/foo") }
37+
it { URI.parse("http://www.example.com").full_path.should eq("/") }
38+
it { URI.parse("http://www.example.com/foo?q=1").full_path.should eq("/foo?q=1") }
39+
it { URI.parse("http://www.example.com/?q=1").full_path.should eq("/?q=1") }
40+
it { URI.parse("http://www.example.com?q=1").full_path.should eq("/?q=1") }
41+
it { URI.parse("http://test.dev/a%3Ab").full_path.should eq("/a%3Ab") }
42+
43+
it "does not add '?' to the end if the query params are empty" do
44+
uri = URI.parse("http://www.example.com/foo")
45+
uri.query = ""
46+
uri.full_path.should eq("/foo")
47+
end
48+
end
4149

4250
describe "normalize" do
4351
it "removes dot notation from path" do

‎src/uri.cr

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ class URI
128128
def full_path
129129
String.build do |str|
130130
str << (@path.try { |p| !p.empty? } ? @path : "/")
131-
str << "?" << @query if @query
131+
if (query = @query) && !query.empty?
132+
str << "?" << query
133+
end
132134
end
133135
end
134136

0 commit comments

Comments
 (0)
Please sign in to comment.