Skip to content

Commit 2c95c01

Browse files
committed
Revert "closes #57 (canonical always clones)"
This reverts commit c77b2bc. This was breaking tests for HTTP::Config. See libwww-perl/HTTP-Message#121
1 parent 9640e69 commit 2c95c01

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

lib/URI.pm

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,21 @@ sub canonical
302302
# Make sure scheme is lowercased, that we don't escape unreserved chars,
303303
# and that we use upcase escape sequences.
304304

305-
# We now clone unconditionally; see
306-
# https://github.com/libwww-perl/URI/issues/57
307-
308-
my $other = $_[0]->clone;
309-
my $scheme = $other->_scheme || "";
305+
my $self = shift;
306+
my $scheme = $self->_scheme || "";
310307
my $uc_scheme = $scheme =~ /[A-Z]/;
311-
my $esc = $$other =~ /%[a-fA-F0-9]{2}/;
312-
return $other unless $uc_scheme || $esc;
313-
314-
$other->_scheme(lc $scheme) if $uc_scheme;
308+
my $esc = $$self =~ /%[a-fA-F0-9]{2}/;
309+
return $self unless $uc_scheme || $esc;
315310

311+
my $other = $self->clone;
312+
if ($uc_scheme) {
313+
$other->_scheme(lc $scheme);
314+
}
316315
if ($esc) {
317-
$$other =~ s{%([0-9a-fA-F]{2})}
318-
{ my $a = chr(hex($1));
316+
$$other =~ s{%([0-9a-fA-F]{2})}
317+
{ my $a = chr(hex($1));
319318
$a =~ /^[$unreserved]\z/o ? $a : "%\U$1"
320-
}ge;
319+
}ge;
321320
}
322321
return $other;
323322
}
@@ -572,12 +571,8 @@ removing the explicit port specification if it matches the default port,
572571
uppercasing all escape sequences, and unescaping octets that can be
573572
better represented as plain characters.
574573
575-
Before version 1.75, this method would return the original unchanged
576-
C<$uri> object if it detected nothing to change. To make the return
577-
value consistent (and since the efficiency gains from this behaviour
578-
were marginal), this method now unconditionally returns a clone. This
579-
means idioms like C<< $uri->clone->canonical >> are no longer
580-
necessary.
574+
For efficiency reasons, if the $uri is already in normalized form,
575+
then a reference to it is returned instead of a copy.
581576
582577
=item $uri->eq( $other_uri )
583578

t/generic.t

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use strict;
22
use warnings;
33

4-
print "1..49\n";
4+
print "1..48\n";
55

66
use URI;
7-
use Scalar::Util qw(refaddr);
87

98
my $foo = URI->new("Foo:opaque#frag");
109

@@ -218,8 +217,3 @@ $old = $foo->query("q");
218217
print "not " unless !defined($old) && $foo eq "?q";
219218
print "ok 48\n";
220219

221-
# canonical must always be a clone
222-
my $c1 = $foo->canonical; # canonicalize first
223-
my $c2 = $c1->canonical; # canonicalize again
224-
print 'not ' if refaddr($c1) == refaddr($c2) or $$c1 ne $$c2;
225-
print "ok 49\n";

0 commit comments

Comments
 (0)