diff options
author | Eito Katagiri <eitoball@gmail.com> | 2013-10-12 20:47:57 +0900 |
---|---|---|
committer | Eito Katagiri <eitoball@gmail.com> | 2015-07-02 09:53:34 +0900 |
commit | c7fc843431ffd2b775cc798d4c2c844fee3c9958 (patch) | |
tree | 553ea6d398127b3afe2385bdd5f4211b4354e8d3 /activesupport | |
parent | 776e5991a9abf11818cb803e80976cea8b454c17 (diff) | |
download | rails-c7fc843431ffd2b775cc798d4c2c844fee3c9958.tar.gz rails-c7fc843431ffd2b775cc798d4c2c844fee3c9958.tar.bz2 rails-c7fc843431ffd2b775cc798d4c2c844fee3c9958.zip |
fix pluralize behavior for words that consist of non-ascii characters
The code below returns "猫" in 3.2, but "猫s" in 4.0.
```ruby
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable "猫"
end
"猫".pluralize
```
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 2 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index be369d21c6..cb36a16a51 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -372,7 +372,7 @@ module ActiveSupport def apply_inflections(word, rules) result = word.to_s.dup - if word.empty? || inflections.uncountables.include?(result.downcase[/\b\w+\Z/]) + if word.empty? || inflections.uncountables.include?(result.downcase[/\b\p{Word}+\Z/]) result else rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) } diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index a0764f6d6b..56bc6bb99f 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require 'abstract_unit' require 'active_support/inflector' @@ -31,6 +32,14 @@ class InflectorTest < ActiveSupport::TestCase assert_equal "", ActiveSupport::Inflector.pluralize("") end + def test_pluralize_for_words_with_non_ascii_characters + ActiveSupport::Inflector.inflections do |inflect| + inflect.uncountable "猫" + end + assert_equal "猫", ActiveSupport::Inflector.pluralize("猫") + ActiveSupport::Inflector.inflections.uncountables.pop + end + ActiveSupport::Inflector.inflections.uncountable.each do |word| define_method "test_uncountability_of_#{word}" do assert_equal word, ActiveSupport::Inflector.singularize(word) |