Skip Menu |

This queue is for tickets about the String-Tagged CPAN distribution.

Report information
The Basics
Id: 100409
Status: resolved
Priority: 0/
Queue: String-Tagged

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.11
Fixed in: 0.12



Subject: ->split breaks tag lengths
$ perl -MString::Tagged -E 'my $s = String::Tagged->new->append( "one " )->append_tagged( "two", tag => 1 )->append( " three" ); print $s->debug_sprintf; print +( $s->split( qr/\n/ ) )[0]->debug_sprintf;' one two three [-] tag => 1 one two three [-----] tag => 1 Seems to be applying the tag -end- position as the new length in the split chunk. -- Paul Evans
Turned out to be a more fundamental bug in the ->substr method. Quite how I've never noticed that before I'm not sure... -- Paul Evans
Subject: rt100409.patch
=== modified file 'lib/String/Tagged.pm' --- lib/String/Tagged.pm 2014-11-14 17:43:14 +0000 +++ lib/String/Tagged.pm 2014-11-17 15:56:22 +0000 @@ -340,7 +340,7 @@ $ts = -1 if $ts < 0 or $tf & FLAG_ANCHOR_BEFORE; $te = -1 if $te > $end or $tf & FLAG_ANCHOR_AFTER; - $ret->apply_tag( $ts, $te, $tn => $tv ); + $ret->apply_tag( $ts, $te - $ts, $tn => $tv ); } return $ret; === modified file 't/06tags-substr.t' --- t/06tags-substr.t 2013-03-15 21:39:20 +0000 +++ t/06tags-substr.t 2014-11-17 15:56:22 +0000 @@ -91,4 +91,20 @@ ], 'tags list after prepend substr' ); +# ->substr accessor +{ + my $str = String::Tagged->new + ->append_tagged( "one", one => 1 ) + ->append ( " " ) + ->append_tagged( "two", two => 2 ) + ->append ( " rest of the string" ); + + my $sub = $str->substr( 3, 9 ); + is( $sub->str, " two rest", '$sub->str' ); + + my $e = $sub->get_tag_extent( 1, "two" ); + is( $e->start, 1, 'two tag starts at 1' ); + is( $e->length, 3, 'two tag length is 3' ); +} + done_testing; === modified file 't/32split.t' --- t/32split.t 2014-11-14 16:37:23 +0000 +++ t/32split.t 2014-11-17 15:56:22 +0000 @@ -19,6 +19,20 @@ '->split returns correct strings' ); } +# split preserves tags (RT100409) +{ + my $str = String::Tagged->new + ->append ( "one " ) + ->append_tagged( "two", tag => 1 ) + ->append ( " three\nfour" ); + + my @lines = $str->split( qr/\n/ ); + + my $e = $lines[0]->get_tag_extent( index( $str->str, "two" ), "tag" ); + is( $e->start, 4, '$e->start of copied tag' ); + is( $e->length, 3, '$e->length of copied tag' ); +} + # split with limit { my $str = String::Tagged->new( "command with some arguments" );
Released in 0.12 -- Paul Evans