This project is archived and is in readonly mode.
[PATCH] Fix ActiveSupport::Multibyte::Chars#slice for empty strings when starting offset is negative
Reported by ronin-56076 (at lighthouseapp) | May 28th, 2010 @ 07:22 AM
ActiveSupport::Multibyte::Chars#slice crashes for a negative starting offset if the string is empty.
Steps to reproduce:
$ script/console
Loading development environment (Rails 2.3.8)
rails(test)> 'test'.slice(-1, 1)
=> "t"
rails(test)> ''.slice(-1, 1)
=> nil
rails(test)> 'test'.mb_chars.slice(-1, 1)
=> #<ActiveSupport::Multibyte::Chars:0x103979830 @wrapped_string="t">
rails(test)> ''.mb_chars.slice(-1, 1)
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.pack
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/multibyte/chars.rb:347:in `slice'
from (irb):4
See the attached patch.
Comments and changes to this ticket
-
ronin-56076 (at lighthouseapp) May 30th, 2010 @ 06:18 AM
- Tag changed from patch to activesupport, chars, multibyte, patch
-
Norman Clarke June 30th, 2010 @ 01:51 PM
- Tag changed from activesupport, chars, multibyte, patch to activesupport, chars, multibyte, patch, verified
- Assigned user set to José Valim
This no longer applies to Rails master after recent changes; here's an updated patch that now applies.
+1 on this, it's a simple change that makes the behavior of the proxy class match Ruby's String#slice.
-
Repository June 30th, 2010 @ 02:09 PM
- State changed from new to resolved
(from [265b7c5edfe9b60d1ab547bfef569d94df05b8e9]) Fix ActiveSupport::Multibyte::Chars#slice for empty strings when starting offset is negative [#4717 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/265b7c5edfe9b60d1ab547bfef569d...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 4717 [PATCH] Fix ActiveSupport::Multibyte::Chars#slice for empty strings when starting offset is negative (from [265b7c5edfe9b60d1ab547bfef569d94df05b8e9]) Fix Act...