forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't print query params if they are empty
I found this while investigating this issue on Lucky: luckyframework/lucky#214 It turns out that because I parsed the query params in that handler it set the URI#query to `""`. This caused `HTTP::Request#resource` to add an extra `?` to the end of the path, even though the query params were empty. This PR fixes the issue by also checking for an empty string before printing `?`
- Loading branch information
1 parent
1978c8b
commit 326aa17
Showing
2 changed files
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,20 @@ describe "URI" do | |
assert_uri("/foo?q=1", path: "/foo", query: "q=1") | ||
assert_uri("mailto:[email protected]", scheme: "mailto", path: nil, opaque: "[email protected]") | ||
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters