Skip Menu |

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

Report information
The Basics
Id: 126011
Status: new
Priority: 0/
Queue: String-Util

People
Owner: MIKO [...] cpan.org
Requestors: ice [...] extreme.hu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.01
Fixed in: (no value)



Subject: trim(..., right => ) broken
Copy-paste bug makes trim() mishandle the 'right' option. Fix: --- a/lib/String/Util.pm +++ b/lib/String/Util.pm @@ -229,7 +229,7 @@ sub trim { { $val =~ s|^\s+||s } # trim right - if ( defined($opts{'right'}) ? $opts{'left'} : 1 ) + if ( defined($opts{'right'}) ? $opts{'right'} : 1 ) { $val =~ s|\s+$||s } }; Attached is the full patch complete with updated tests.
Subject: String::Util.diff
diff --git a/lib/String/Util.pm b/lib/String/Util.pm index 631641c..ea6f26c 100644 --- a/lib/String/Util.pm +++ b/lib/String/Util.pm @@ -229,7 +229,7 @@ sub trim { { $val =~ s|^\s+||s } # trim right - if ( defined($opts{'right'}) ? $opts{'left'} : 1 ) + if ( defined($opts{'right'}) ? $opts{'right'} : 1 ) { $val =~ s|\s+$||s } }; diff --git a/t/test.t b/t/test.t index 5f6b470..2b917c5 100644 --- a/t/test.t +++ b/t/test.t @@ -10,7 +10,7 @@ use Test::Toolbox; # use Test::Toolbox::Idocs; # plan tests -rtplan 37, autodie=>$ENV{'IDOCSDEV'}, xverbose=>$ENV{'IDOCSDEV'}; +rtplan 42, autodie=>$ENV{'IDOCSDEV'}, xverbose=>$ENV{'IDOCSDEV'}; my $n0 = 'String::Util'; @@ -79,6 +79,31 @@ if (1) { ##i # undef returns undef rtcomp "$n1 - undef returns undef", trim(undef), undef; + + # right trim + $val = ' steve fred '; + $val = rtrim($val); + rtcomp "$n1 - rtrim", $val, ' steve fred'; + + # right trim, with trim() argument + $val = ' steve fred '; + $val = trim($val, left => 0, right => 1); + rtcomp "$n1 - trim right only", $val, ' steve fred'; + + # left trim + $val = ' steve fred '; + $val = ltrim($val); + rtcomp "$n1 - ltrim", $val, 'steve fred '; + + # left trim, with trim() argument + $val = ' steve fred '; + $val = trim($val, left => 1, right => 0); + rtcomp "$n1 - trim left only", $val, 'steve fred '; + + # trim, no trim + $val = ' steve fred '; + $val = trim($val, left => 0, right => 0); + rtcomp "$n1 - trim, no trim", $val, ' steve fred '; } # # trim