@@ -302,21 +302,22 @@ sub canonical
302
302
# Make sure scheme is lowercased, that we don't escape unreserved chars,
303
303
# and that we use upcase escape sequences.
304
304
305
- my $self = shift ;
306
- my $scheme = $self -> _scheme || " " ;
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 || " " ;
307
310
my $uc_scheme = $scheme =~ / [A-Z]/ ;
308
- my $esc = $$self =~ / %[a-fA-F0-9]{2}/ ;
309
- return $self unless $uc_scheme || $esc ;
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 ;
310
315
311
- my $other = $self -> clone;
312
- if ($uc_scheme ) {
313
- $other -> _scheme(lc $scheme );
314
- }
315
316
if ($esc ) {
316
- $$other =~ s { %([0-9a-fA-F]{2})}
317
- { my $a = chr (hex ($1 ));
317
+ $$other =~ s { %([0-9a-fA-F]{2})}
318
+ { my $a = chr (hex ($1 ));
318
319
$a =~ / ^[$unreserved ]\z /o ? $a : " %\U $1 "
319
- }ge ;
320
+ }ge ;
320
321
}
321
322
return $other ;
322
323
}
@@ -571,8 +572,12 @@ removing the explicit port specification if it matches the default port,
571
572
uppercasing all escape sequences, and unescaping octets that can be
572
573
better represented as plain characters.
573
574
574
- For efficiency reasons, if the $uri is already in normalized form,
575
- then a reference to it is returned instead of a copy.
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.
576
581
577
582
=item $uri->eq( $other_uri )
578
583
0 commit comments