Refactor test to move makeCompliant tests out of urlize. Tweak makeCompliant for speed and clarity.
This commit is contained in:
parent
aed2c13f52
commit
1abe035183
2 changed files with 26 additions and 21 deletions
|
|
@ -405,9 +405,8 @@ sub makeCompliant {
|
|||
$url =~ s{\s+$}{}; # remove trailing whitespace
|
||||
$url =~ s{^/+}{}; # remove leading slashes
|
||||
$url =~ s{/+$}{}; # remove trailing slashes
|
||||
$url =~ s{[^\w/:._-]+}{-}g; # replace anything aside from word or other allowed characters with dashes
|
||||
$url =~ s{//+}{/}g; # remove double slashes
|
||||
$url =~ s{--+}{-}g; # remove double dashes
|
||||
$url =~ s{[^\w/:.-]+}{-}g; # replace anything aside from word or other allowed characters with dashes
|
||||
$url =~ tr{/-}{/-}s; # replace multiple slashes and dashes with singles.
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
|
@ -530,16 +529,14 @@ The string to urlize.
|
|||
=cut
|
||||
|
||||
sub urlize {
|
||||
my $self = shift;
|
||||
my ($value);
|
||||
$value = lc(shift); #lower cases whole string
|
||||
my $self = shift;
|
||||
my $value = lc(shift); #lower cases whole string
|
||||
$value = $self->makeCompliant($value);
|
||||
|
||||
# remove /./ or /../
|
||||
$value =~ s{(^|/)(?:\.\.?/)*}{$1}g;
|
||||
|
||||
# remove trailing slashes
|
||||
$value =~ s/\/$//;
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue