Skip to content

Commit

Permalink
Merge pull request #8156 from fredwu/acronym_fix-master
Browse files Browse the repository at this point in the history
Fix for inflector's incorrect camelCase replacement for acronyms
  • Loading branch information
fxn committed Mar 16, 2013
2 parents 9a421aa + 26aa265 commit 867dc17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ## ## 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. * Fix deletion of empty directories in ActiveSupport::Cache::FileStore.


*Charles Jones* *Charles Jones*
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/inflector/methods.rb
Expand Up @@ -91,7 +91,7 @@ def underscore(camel_cased_word)
word = camel_cased_word.to_s.dup word = camel_cased_word.to_s.dup
word.gsub!('::', '/') word.gsub!('::', '/')
word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" } 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') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
word.tr!("-", "_") word.tr!("-", "_")
word.downcase! word.downcase!
Expand Down
2 changes: 2 additions & 0 deletions activesupport/test/inflector_test.rb
Expand Up @@ -167,11 +167,13 @@ def test_acronyms_camelize_lower
def test_underscore_acronym_sequence def test_underscore_acronym_sequence
ActiveSupport::Inflector.inflections do |inflect| ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym("API") inflect.acronym("API")
inflect.acronym("APIs")
inflect.acronym("JSON") inflect.acronym("JSON")
inflect.acronym("HTML") inflect.acronym("HTML")
end end


assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI")) assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI"))
assert_equal("namespaced/apis", ActiveSupport::Inflector.underscore("Namespaced::APIs"))
end end


def test_underscore def test_underscore
Expand Down

0 comments on commit 867dc17

Please sign in to comment.