Changeset 402 for veekun/trunk

Show
Ignore:
Timestamp:
01/31/08 12:30:29 (10 months ago)
Author:
eevee
Message:

BETTER fix for bbcode infinite loop, now that I realize why the original code looked like it did.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/lib/Vee/BBCode.pm

    r401 r402  
    3232# BUGS: 
    3333#  - replace won't work with no_close 
    34 #  - replace won't work when nested 
    3534our %tags = ( 
    3635    b       => { param => 0, start => '<strong class="bbcode-b">', end => '</strong>' }, 
     
    8584    for my $tag (keys %tags) { 
    8685        if (exists $tags{$tag}{replace}) { 
    87             $input =~ s: (.*) \[ $tag \] (.+?) \[ / $tag \] : $1 . $tags{$tag}{replace}->(undef, $2) :gexis; 
    88             $input =~ s: (.*) \[ $tag = (.+?) \] (.+?) \[ / $tag \] : $1 . $tags{$tag}{replace}->($2, $3) :gexis; 
     86            while ($input =~ / \[ $tag ( = .+? )? \] /sx) { 
     87                # .* at the beginning ensures we catch innermost nestings first 
     88                $input =~ s: (.*) \[ $tag \] (.+?) \[ / $tag \] : $1 . $tags{$tag}{replace}->(undef, $2) :gexis; 
     89                $input =~ s: (.*) \[ $tag = (.+?) \] (.+?) \[ / $tag \] : $1 . $tags{$tag}{replace}->($2, $3) :gexis; 
     90            } 
    8991        } else { 
    9092            $input =~ s: \[ $tag \] : $tags{$tag}{start}->() :gexi;