# New Ticket Created by  Ron Schmidt 
# Please include the string:  [perl #57722]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=57722 >


Index: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir    (revision 30090)
+++ src/builtins/any-str.pir    (working copy)
@@ -89,8 +89,10 @@
     len = self.'chars'()
   have_len:
     if len >= 0 goto len_done
+    if start < 0 goto neg_start
     $I0 = self.'chars'()
     len += $I0
+  neg_start:    
     len -= start
   len_done:
     $S0 = self
Index: t/spec/S29-str/substr.t
===================================================================
--- t/spec/S29-str/substr.t     (revision 21834)
+++ t/spec/S29-str/substr.t     (working copy)
@@ -2,7 +2,7 @@
 
 use Test;
 
-plan 42;
+plan 43;
 
 # L<S29/Str/=item substr>
 
@@ -24,6 +24,7 @@
     is(substr($str, 0, -2), "foob", "from beginning, with negative length");
     is(substr($str, 2, -2), "ob", "in middle, with negative length");
     is(substr($str, 3, -3), "", "negative length - gives empty string");
+    is(substr($str, -4, -1), "oba", "negative start and length ");
 
     is($str, "foobar", "original string still not changed");
 };
 From the irc log for today (8/7)

15:50 </perl6/2008-08-07#i_426959>      ron     perl6: my $a = '0123456'; say 
substr($a, -5, -2);
15:50 </perl6/2008-08-07#i_426960>      p6eval  elf 21826, pugs: OUTPUT[234?]
15:50 </perl6/2008-08-07#i_426961>      
        ..rakudo 29834: OUTPUT[23456?]


perl5 agrees with the pugs output.

Attached patch fixes the problem and includes a test in: S29-str/substr.t

Ron


Reply via email to