Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substr with negative start and length gives different results from perl5 #219

Closed
p6rt opened this issue Aug 7, 2008 · 5 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 7, 2008

Migrated from rt.perl.org#57722 (status was 'resolved')

Searchable as RT57722$

@p6rt
Copy link
Author

p6rt commented Aug 7, 2008

From @ronaldxs

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

@p6rt
Copy link
Author

p6rt commented Aug 7, 2008

From @ronaldxs

substr_fix.diff
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");
 };

@p6rt
Copy link
Author

p6rt commented Dec 17, 2008

From @jnthn

On Thu Aug 07 12​:41​:32 2008, ronaldxs wrote​:

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

Applied Rakudo patch as r34031 and added the test.

Many thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Dec 17, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 17, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Dec 17, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant