Skip to content


Fix for inflector's incorrect camelCase replacement for acronyms #8156

merged 2 commits into from

5 participants


Description of this bug: #8015


PR for 3.2 branch: #8155

Ruby on Rails member

/cc @fxn


Hi @fxn, would you mind taking a look at this PR as it's been quite a while and it'd be awesome if this is going to get addressed. :)

Ruby on Rails member

Can you please rebase this one? We'll apply.


Thanks @fxn , rebased!

Ruby on Rails member

Awesome! Thanks @fredwu and @fxn


@fxn fxn merged commit 867dc17 into rails:master

This caused breakage in actionpack/test/controller/force_ssl_test.rb, and will likely break production apps as well. Controllers such as ForceSSLOnlyAction now have a path of /force_sslonly_action when previously it would have been /force_ssl_only_action.

Ruby on Rails member

@macksmind you are awesome. I started getting errors on the rails-api build for this exact situation, and hadn't found the time to track it down.

Ruby on Rails member

Have to be reverted then, the example reported in the original PR needs a fix, but the patch is not good.

I am out though, Steve could you revert please?

Ruby on Rails member


@steveklabnik steveklabnik added a commit that referenced this pull request
@steveklabnik steveklabnik Revert "Merge pull request #8156 from fredwu/acronym_fix-master"
This reverts commit 867dc17, reversing
changes made to 9a421aa.

This breaks anyone who's using ForceSSL:

Please see comments on #8156 for some discussion.
Ruby on Rails member

Reveted in feaa6e2

Ruby on Rails member



I'm taking a look at this and will fix my patch.

@fredwu fredwu added a commit to fredwu/rails that referenced this pull request
@fredwu fredwu Fixed a bug where the inflector would replace camelCase strings and d…
…isregarding specified acronyms, fixes #8015, closes #8156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 16, 2013
  1. @fredwu

    Fixed a bug where the inflector would replace camelCase strings and d…

    fredwu committed
    …isregarding specified acronyms, fixes #8015
  2. @fredwu
This page is out of date. Refresh to see the latest.
4 activesupport/
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Fixed a bug in Inflector#underscore where acroynms are incorrectly parsed as camelCases.
+ *Fred Wu*
* Fix deletion of empty directories in ActiveSupport::Cache::FileStore.
*Charles Jones*
2 activesupport/lib/active_support/inflector/methods.rb
@@ -91,7 +91,7 @@ def underscore(camel_cased_word)
word = camel_cased_word.to_s.dup
word.gsub!('::', '/')
word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
+ word.gsub!(/(?!#{inflections.acronym_regex})\b([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')!("-", "_")
2 activesupport/test/inflector_test.rb
@@ -167,11 +167,13 @@ def test_acronyms_camelize_lower
def test_underscore_acronym_sequence
ActiveSupport::Inflector.inflections do |inflect|
+ inflect.acronym("APIs")
assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI"))
+ assert_equal("namespaced/apis", ActiveSupport::Inflector.underscore("Namespaced::APIs"))
def test_underscore
Something went wrong with that request. Please try again.