JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6863

multibyte strings after String#slice get wrong result on String#index(rindex)

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.7, JRuby 1.7.0.pre2
    • Fix Version/s: JRuby 1.7.0.RC1
    • Component/s: Java Integration
    • Labels:
      None
    • Environment:
      Jruby 1.7.0 pre2
      OS X 10.8

      java version "1.6.0_33"
      Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
      Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
    • Patch Submitted:
      Yes
    • Number of attachments :
      2

      Description

      runnning follow code

      1. coding: utf-8
        str = "あいうえおかきく‘“"
        s = str.slice(3..-1) # => "えおかきく‘“"

      s.index(/[^ ]/) # => 3

      but in CRuby 1.9.3

      1. coding: utf-8
        str = "あいうえおかきく‘“"
        s = str.slice(3..-1)

      s.index(/[^ ]/) # => 0

      String#rindex have similar problem.
      attachment patch file(and spec) will fix this problem.

      1. fix_index.patch
        2 kB
        Tsuyoshi Yamane
      2. test.rb
        0.2 kB
        Tsuyoshi Yamane

        Activity

        Hide
        Tsuyoshi Yamane added a comment -

        I'm sorry. Japanese Character can't display...
        I attach the test program to Attchments.

        Show
        Tsuyoshi Yamane added a comment - I'm sorry. Japanese Character can't display... I attach the test program to Attchments.
        Hide
        Tsuyoshi Yamane added a comment -

        This is test program.

        Show
        Tsuyoshi Yamane added a comment - This is test program.
        Hide
        Charles Oliver Nutter added a comment -

        Wow, what a dreadful flaw! I will apply your fix.

        Show
        Charles Oliver Nutter added a comment - Wow, what a dreadful flaw! I will apply your fix.
        Hide
        Charles Oliver Nutter added a comment -

        Looks like the fix is working, but the regression spec needs to be tweaked to not run in 1.8 mode (since 1.8 handles the length of these multibyte chars differently). Committing shortly.

        Show
        Charles Oliver Nutter added a comment - Looks like the fix is working, but the regression spec needs to be tweaked to not run in 1.8 mode (since 1.8 handles the length of these multibyte chars differently). Committing shortly.
        Hide
        Charles Oliver Nutter added a comment -
        commit 9901bf4d8f353229a440f8b8e0000a47ded6287f
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Mon Aug 27 12:58:39 2012 -0500
        
            Fix JRUBY-6863
            
            multibyte strings after String#slice get wrong result on String#index(rindex)
            
            Patch and test by Tsuyoshi Yamane <yama.tsuyo@gmail.com>
        
        :000000 100644 0000000... 370c663... A	spec/regression/JRUBY-6863_index_after_slice_spec.rb
        :100644 100644 93d6813... 8397e34... M	src/org/jruby/RubyString.java
        
        Show
        Charles Oliver Nutter added a comment - commit 9901bf4d8f353229a440f8b8e0000a47ded6287f Author: Charles Oliver Nutter <headius@headius.com> Date: Mon Aug 27 12:58:39 2012 -0500 Fix JRUBY-6863 multibyte strings after String#slice get wrong result on String#index(rindex) Patch and test by Tsuyoshi Yamane <yama.tsuyo@gmail.com> :000000 100644 0000000... 370c663... A spec/regression/JRUBY-6863_index_after_slice_spec.rb :100644 100644 93d6813... 8397e34... M src/org/jruby/RubyString.java
        Hide
        Tsuyoshi Yamane added a comment -

        In terms of 1.8 mode my consideration was missing.
        Thank you for your application!

        Show
        Tsuyoshi Yamane added a comment - In terms of 1.8 mode my consideration was missing. Thank you for your application!

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Tsuyoshi Yamane
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: