Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Correctly apply inflection rules on uncountable multi-word strings.

Currently, apply_inflections does not take into account that the input might be a multi-word string separated by underscore. (tableize etc relies on this behavior to work correctly.) This bug affects only uncountable multi-word strings separated by underscores:

   "funky jeans".singularize # => "funky jeans"
   "client information".pluralize # => "client information"

   "funky_jeans".singularize # => "funky_jean"
   "client_information".pluralize # => "client_informations"

It's also worth pointing out that "funky_jeans".singularize used to work correctly before 9b4622a, which was merged almost 2 years ago so this is essentially broken since Rails 3.

On the other hand, it appears that "client_information".pluralize has always been broken, so this does change the behavior of tableize and could potentially break some older apps out there.

Closes #7132.
  • Loading branch information...
commit fba8a6a10e2530081c96ad723ca75fd62264795e 1 parent 4d7a102
Godfrey Chan authored
2  activesupport/lib/active_support/inflector/methods.rb
View
@@ -313,7 +313,7 @@ def const_regexp(camel_cased_word) #:nodoc:
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[/[a-z0-9]+\Z/])
result
else
rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
3  activesupport/test/inflector_test_cases.rb
View
@@ -62,6 +62,9 @@ module InflectorTestCases
"old_news" => "old_news",
"news" => "news",
+ "funky_jeans" => "funky_jeans",
+ "stinky_fish" => "stinky_fish",
+
"series" => "series",
"species" => "species",
Please sign in to comment.
Something went wrong with that request. Please try again.