String#scan doesn't restore backref
-----------------------------------

                 Key: JRUBY-1195
                 URL: http://jira.codehaus.org/browse/JRUBY-1195
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
         Environment: [EMAIL PROTECTED]
            Reporter: Anders Bengtsson


This snippet prints "hello" in MRI, but nil in JRuby:

{noformat}
"%mhello".scan(/%m/) do |v|
  "m" =~ /x/
end
p $'
{noformat}

This breaks Needle's unit tests (but possibly not Needle itself).

Comparing the String#scan implementations of MRI and JRuby shows that MRI takes 
some care to keep the back-refs, which JRuby doesn't.

This one-liner fixes the case above, but probably isn't enough:

{noformat}
Index: src/org/jruby/RubyString.java
===================================================================
--- src/org/jruby/RubyString.java       (revision 3969)
+++ src/org/jruby/RubyString.java       (working copy)
@@ -2529,6 +2529,8 @@
             }
         }
 
+        context.setBackref(matchdata(runtime, str, mat, utf8));
+
         return this;
     }
{noformat}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to