gisle/uri — pull request #5 by hiratara (2012-01-27 07:56:32+00:00)
Title: Don't omit "/" if it has QUERY_STRING.

RFC 1738 says, `If neither <path> nor <searchpart> is present, the "/" may also be omitted.'.

http://www.rfc-editor.org/rfc/rfc1738.txt

So we can't omit "/" if the URL has '?' and QUERY_STRINGs.

I thought that the following patch is better than this pull-req, but it makes t/old-base.t broken.

```diff
diff --git a/URI/http.pm b/URI/http.pm
index cb69822..8631e40 100644
--- a/URI/http.pm
+++ b/URI/http.pm
@@ -13,7 +13,7 @@ sub canonical
my $other = $self->SUPER::canonical;

my $slash_path = defined($other->authority) &&
- !length($other->path) && !defined($other->query);
+ !length($other->path) && defined($other->query);

if ($slash_path) {
$other = $other->clone if $other == $self;
diff --git a/t/http.t b/t/http.t
index 2b8c44b..65e32cd 100644
--- a/t/http.t
+++ b/t/http.t
@@ -1,6 +1,6 @@
#!perl -w

-print "1..15\n";
+print "1..17\n";

use URI;

@@ -61,3 +61,12 @@ $u = URI->new("http://%77%77%77%2e%70%65%72%6c%2e%63%6f%6d/%7
print "not " unless $u->canonical eq "http://www.perl.com/pub/a/2001/08/27/bjor
print "ok 15\n";

+# RFC 1738: "/" can't be ommited when is present.
+$u = URI->new("http://localhost?p=1");
+print "not " unless $u->canonical eq "http://localhost/?p=1";
+print "ok 16\n";
+
+$u = URI->new("http://localhost");
+print "not " unless $u->canonical eq "http://localhost";
+print "ok 17\n";
+
```