Skip to content
This repository

Inconsistent inflector behaviour for uncountable words in a multi-word string separated by underscores #7132

Closed
chancancode opened this Issue · 5 comments

5 participants

Godfrey Chan Steve Klabnik Blake Watters Rafael Mendonça França Xavier Noria
Godfrey Chan
Collaborator
# Single-word + uncountables = no problem!
"information".singularize # => "information"
"information".pluralize # => "information"

# Multi-word + spaces + countables = no problem!
"weird bugs".singularize # => "weird bug"
"weird bug".pluralize # => "weird bugs"

# Multi-word + spaces + uncountables = no problem!
"funky jeans".pluralize # => "funky jeans"
"funky jeans".singularize # => "funky jeans"

# Multi-word + underscores + countables = no problem!
"weird_bugs".singularize # => "weird_bug"
"weird_bug".pluralize # => "weird_bugs"

# Multi-word + underscores + uncountables = BOOM!
"funky_jeans".singularize # => "funky_jean"
"client_information".pluralize # => "client_informations"

I consider this a bug because...
1. According to this test case, pluralizing/singularizing a multi-word string is a supported feature
2. According to this test cases, pluralizing/singularizing a multi-word string separated by underscores is a supported feature
3. tableize depends on 2.
4. "funky_jeans".singularize used to work before 9b4622a:

mbp:godfrey rails [(no branch)] $ git checkout baebe7d0d5c82cc7bb0570ae7d17a947f9bf58f7
HEAD is now at baebe7d... Avoid Bundler Resolver bug until they solve the issue
mbp:godfrey rails [(no branch)] $ irb -Iactivesupport/lib
>> require 'active_support/all'
=> true
>> 'funky_jeans'.singularize
=> "funky_jeans"

However, as far as I know, "client_information".pluralize have always been (incorrectly) returning "client_informations", meaning that fixing this might break certain apps out there. singularize and pluralize used to go through different code paths, but 52fa34f merged them into a single path, so it's no longer possible to just fix the bug introduced in 9b4622a without affecting the other direction as well. (I don't think that's a very reasonable behaviour anyways.)

Godfrey Chan chancancode referenced this issue from a commit in chancancode/rails
Godfrey Chan chancancode 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.
fba8a6a
Steve Klabnik
Collaborator

Generally, the inflector is frozen. I'll defer to @fxn on this particular case, though.

Blake Watters

+1 This is an irritating case that is easily fixed by applying this existing rules across the words

Rafael Mendonça França
Owner

@fxn could you take a look?

Godfrey Chan
Collaborator

Since the PR fixing this issue (#7134) has been rejected, this should probably be closed as well!

Xavier Noria
Owner

Yeah, this is something that has been discussed in the past. Basically, the behaviour of singularize and friends on multi-word strings is undefined, their contract only includes whole words.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.