Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Bug Fixes
* Fencepost recrufting order [github 12] (lazarus)

20160806 Sat Aug 6 13:36:14 PDT 2016
Distribution
* Homepage is now metacpan
Expand Down
17 changes: 13 additions & 4 deletions lib/URI/Find.pm
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,19 @@ sub decruft {
if( $orig_match =~ s/([\Q$cruftSet\E]+)$// ) {
# urls can end with HTML entities if found in HTML so let's put back semicolons
# if this looks like the case
my $cruft = $1;
my $cruft = my $orig_cruft = $1;

if( $cruft =~ /^;/ && $orig_match =~ /\&(\#[1-9]\d{1,3}|[a-zA-Z]{2,8})$/) {
$orig_match .= ';';
$cruft =~ s/^;//;
}

while( my($open, $close) = each %balanced_cruft ) {
my $compare = sub { index( $orig_cruft, $_[ 1 ] )
<=> index( $orig_cruft, $_[ 0 ] ) };

for my $open (sort { $compare->( $a, $b ) } keys %balanced_cruft) {
my $close = $balanced_cruft{ $open };

$self->recruft_balanced(\$orig_match, \$cruft, $open, $close);
}

Expand All @@ -355,9 +361,12 @@ sub recruft_balanced {
my $open_count = () = $$orig_match =~ m{\Q$open}g;
my $close_count = () = $$orig_match =~ m{\Q$close}g;

if ( $$cruft =~ /\Q$close\E$/ && $open_count == ( $close_count + 1 ) ) {
$open eq $close and $open_count and $open_count == $close_count
and $open_count % 2 > 0 and $close_count--;

if ($$cruft =~ m{ \A \Q$close\E }mx && $open_count == ($close_count + 1) ) {
$$orig_match .= $close;
$$cruft =~ s/\Q$close\E$//;
$$cruft =~ s{ \A \Q$close\E }{}mx;
}

return;
Expand Down
4 changes: 4 additions & 0 deletions t/filter.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ my @tasks = (

# Non-URL nested inside brackets
[q{<a href="foo://example&.com">}, q{<a href="foo://example&amp;.com">}],
# Does not reorder the fencepost cruft. Issue #12
[q{e:('')}, q{e:('')}],
[q{ Supporter Number:[*data('1.supporter_number')|html*] },
q{ Supporter Number:[*data('1.supporter_number')|html*] }],
);

for my $task (@tasks) {
Expand Down