Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9142 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Add support for []= on ActiveSupport::Multibyte::Chars

Reported by: ewan Assigned to: core
Priority: normal Milestone: 1.x
Component: ActiveSupport Version: edge
Severity: normal Keywords: multibyte verified
Cc:

Description

Try the following:

foo = "abâ"
foo.chars[2] = "c"

foo.chars now tells me it's

#<ActiveSupport::Multibyte::Chars:0xb781d4ec @string="abc\242">

..hmm... if that doesn't work, the following shouldn't work...

foo = "abâ"
foo.chars[2,2] = "c"

... but lo and behold, we have "abc" for foo.chars.. but, funnily enough, the following

foo = "abâ"
foo.chars[1,2] = "c"

...tells me that foo.chars is #<ActiveSupport::Multibyte::Chars:0xb77f5d98 @string="ac\242">. as far as I can see neither Chars nor UTF8Handler has []= defined - though I don't see why one of them wouldn't - but then why does the second case work?

Attachments

support_[]=_method_on_utf8_handler.diff (3.7 kB) - added by manfred on 07/30/07 20:25:09.

Change History

07/30/07 17:07:18 changed by manfred

Yes, you're right, the UTF-8 handler doesn't implement []= so the method is redirected to the underlying string. The reason that foo[2,2] = 'c' works is because [2,2] says "give me two bytes starting from index 2", that works perfectly on a bytestring when the character is encoded with two bytes.

It's pretty straightforward to implement support for []=. I'll get on it.

07/30/07 20:25:09 changed by manfred

  • attachment support_[]=_method_on_utf8_handler.diff added.

07/30/07 20:26:22 changed by manfred

I've added a patch to support the []= method on the UTF-8 handler. Can you try it out on your code?

07/30/07 20:30:52 changed by norbert

  • keywords set to multibyte.
  • milestone set to 1.x.

Crushin', Manfred. +1

07/30/07 20:37:33 changed by manfred

  • summary changed from ActiveSupport::Multibyte::Chars []= behaves unpredictably for utf8 strings to [PATCH[ Add support for []= on ActiveSupport::Multibyte::Chars.

07/30/07 20:38:02 changed by manfred

  • summary changed from [PATCH[ Add support for []= on ActiveSupport::Multibyte::Chars to [PATCH] Add support for []= on ActiveSupport::Multibyte::Chars.

07/30/07 20:49:11 changed by lifofifo

+1

07/30/07 20:55:53 changed by ewan

yep, +1.

07/30/07 20:58:48 changed by ewan

  • keywords changed from multibyte to multibyte verified.

07/31/07 04:59:13 changed by marcel

  • status changed from new to closed.
  • resolution set to fixed.

(In [7257]) Add support for []= on ActiveSupport::Multibyte::Chars. Closes #9142. [ewan, manfred]