aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2006-10-12 21:03:32 +0000
committerMichael Koziarski <michael@koziarski.com>2006-10-12 21:03:32 +0000
commit48cef84150d2c5f7be351787d0584626f5b8155a (patch)
tree3a884eefc39b41e0a7f5c2abd4a93eab189d8b82
parentcb927c8774f98c979b4e0466798d74bdd23a79f2 (diff)
downloadrails-48cef84150d2c5f7be351787d0584626f5b8155a.tar.gz
rails-48cef84150d2c5f7be351787d0584626f5b8155a.tar.bz2
rails-48cef84150d2c5f7be351787d0584626f5b8155a.zip
Make core_ext/string/access.rb multibyte safe. Closes #6388 [Manfred Stienstra]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5287 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/string/access.rb10
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb1
3 files changed, 8 insertions, 5 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 9cc032fd04..a94780404e 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make core_ext/string/access.rb multibyte safe. Closes #6388 [Manfred Stienstra]
+
* Make String#chars slicing behaviour consistent with String. Closes #6387 [Manfred Stienstra]
* Pull in latest multibye patch. Closes #6346 [Manfred Stienstra]
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 5d0e0c21aa..cb6da4ab6a 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -10,7 +10,7 @@ module ActiveSupport #:nodoc:
# "hello".at(4) # => "o"
# "hello".at(10) # => nil
def at(position)
- self[position, 1]
+ chars[position, 1]
end
# Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character).
@@ -20,7 +20,7 @@ module ActiveSupport #:nodoc:
# "hello".from(2) # => "llo"
# "hello".from(10) # => nil
def from(position)
- self[position..-1]
+ chars[position..-1]
end
# Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character).
@@ -30,7 +30,7 @@ module ActiveSupport #:nodoc:
# "hello".to(2) # => "hel"
# "hello".to(10) # => "hello"
def to(position)
- self[0..position]
+ chars[0..position]
end
# Returns the first character of the string or the first +limit+ characters.
@@ -40,7 +40,7 @@ module ActiveSupport #:nodoc:
# "hello".first(2) # => "he"
# "hello".first(10) # => "hello"
def first(limit = 1)
- self[0..(limit - 1)]
+ chars[0..(limit - 1)]
end
# Returns the last character of the string or the last +limit+ characters.
@@ -50,7 +50,7 @@ module ActiveSupport #:nodoc:
# "hello".last(2) # => "lo"
# "hello".last(10) # => "hello"
def last(limit = 1)
- self[(-limit)..-1] || self
+ chars[(-limit)..-1] || self
end
end
end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index c7c4d1a05f..47f772ab9b 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -75,6 +75,7 @@ class StringInflectionsTest < Test::Unit::TestCase
assert_equal "o", s.last
assert_equal "llo", s.last(3)
+ assert_equal "hello", s.last(10)
assert_equal 'x', 'x'.first
assert_equal 'x', 'x'.first(4)