Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveSupport::Multibyte::Chars

#3028

ActiveSupport::Multibyte::Chars does not support rindex() , this creates a bug in truncate when using multibyte strings and options[:seperator]

completion of ticket #2582 [PATCH] ActionView::TextHelper Graceful Truncate depends on this, also causes breakage in 3.0 implementation.

Reported by Steve St. Martin · August 10th, 2009 @ 12:05 AM

State: resolved
Milestone: 2.3.4
Assigned to: nobody
Importance: none

Activity

  1. Erik Ostrom
    Erik Ostrom

    Verified, test and patch forthcoming.

    August 10th, 2009 @ 02:38 AM

  2. Erik Ostrom
    Erik Ostrom

    I've attached a patch (including a test).

    August 10th, 2009 @ 02:45 AM

  3. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to Jeremy Kemper
    • State changed from new to open
    • Milestone set to 2.3.4

    Good catch. Could you use git format-patch instead of diff?

    August 10th, 2009 @ 02:54 AM

  4. Elad Meidar
    Elad Meidar
    • Assigned user cleared.

    "Patch does not have a valid email address", attached a working patch.

    August 10th, 2009 @ 02:59 AM

  5. Elad Meidar
    Elad Meidar

    Patch applies to master, tests pass as well.

    August 10th, 2009 @ 03:01 AM

  6. Erik Ostrom
  7. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to Jeremy Kemper

    On Ruby 1.9:

      1) Failure:
    test_rindex_should_return_character_offset(MultibyteCharsUTF8BehaviourTest) [test/multibyte_chars_test.rb:241]:
    12 expected but was
    13.
    

    August 10th, 2009 @ 03:07 AM

  8. Jeremy Kemper
    Jeremy Kemper
    • State changed from open to incomplete

    Applied to master (prematurely): 4dda9b644df5e4386f693a4b7bd00fe787f41a28

    Need to be compat with 1.9 before 2-3-stable backport.

    August 10th, 2009 @ 03:37 AM

  9. Elad Meidar
    Elad Meidar
    • Assigned user cleared.

    i was having a problem with the functionality using RTL languages as values, since rindex always scans left to right, strings were truncated in the wrong way.

    August 10th, 2009 @ 03:58 AM

  10. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to Jeremy Kemper

    August 10th, 2009 @ 04:19 AM

  11. Erik Ostrom
    Erik Ostrom
    • Assigned user cleared.

    Ruby 1.9 helpfully points out that my test is wrong - which means my implementation is, too. Developing...

    August 10th, 2009 @ 04:54 AM

  12. Erik Ostrom
    Erik Ostrom

    I've attached a patch to be applied after my earlier one. The test is fixed so it passes on Ruby 1.9, and the implementation is fixed so it passes the fixed test. The offset parameter wasn't being translated into bytes before calling the underlying string method.

    index had an equivalent bug, which went unnoticed because the test cases all used the default offset, and a 0-character offset translates to 0 bytes. I added some offset tests and fixed the bug in #index.

    I also threw in a couple of negative-offset tests, inspired by #2428 Unicode-aware rindex method, of which this ticket is a duplicate. (Andy Stewart's patch from that one no longer applies cleanly to master, but I wish I'd noticed it earlier.)

    These tests passed (for me) on Ruby 1.9.2 Preview 1 and Ruby 1.8.6.

    August 10th, 2009 @ 07:19 AM

  13. Repository
    Repository
    • State changed from incomplete to committed

    (from [7d16e94d827197d030fdd611db4310396aeb0114]) Correctly handle offsets in Multibyte::Chars#index and #rindex.

    The offset in codepoints was being passed directly to the wrapped string's index/rindex method. Now we translate the offset into bytes first.

    [#3028 ActiveSupport::Multibyte::Chars state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/7d16e94d827197d030fdd611db4310...

    August 10th, 2009 @ 07:33 AM

  14. Repository
    Repository

    (from [4e014379a3c792281138c5a19a5bd74e9435fede]) Correctly handle offsets in Multibyte::Chars#index and #rindex.

    The offset in codepoints was being passed directly to the wrapped string's index/rindex method. Now we translate the offset into bytes first.

    [#3028 ActiveSupport::Multibyte::Chars state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/4e014379a3c792281138c5a19a5bd7...

    August 10th, 2009 @ 07:33 AM

  15. Jeremy Kemper
    Jeremy Kemper
    • Tag changed from 2, 2.3.x, 3, 3.0, bugmash, multibyte to 2, 2.3.x, 3, 3.0, multibyte

    August 10th, 2009 @ 07:34 AM

  16. Rizwan Reza
    Rizwan Reza
    • State changed from committed to resolved

    January 20th, 2010 @ 11:54 AM

  17. Jeremy Kemper
    Jeremy Kemper

    Rizwan, committed == resolved.

    January 21st, 2010 @ 02:04 AM

  18. Andrea Campi
    Andrea Campi
    • Tag changed from 2, 2.3.x, 3, 3.0, multibyte to 2-3-stable, 2.3.x, 3, 3.0, multibyte
    • Importance changed from to

    October 16th, 2010 @ 11:44 PM