diff options
author | Xavier Noria <fxn@hashref.com> | 2013-03-16 07:59:47 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2013-03-16 07:59:47 -0700 |
commit | 867dc1700f32aae6f98c4651bd501597e6b52bc0 (patch) | |
tree | 5b60adcd0d0a902f40b0fb242bb79ce037d3ef38 /activesupport | |
parent | 9a421aaa8285cf2a7ecb1af370748b0337818930 (diff) | |
parent | 26aa26564d16b7830ea4889168adfad8468186b7 (diff) | |
download | rails-867dc1700f32aae6f98c4651bd501597e6b52bc0.tar.gz rails-867dc1700f32aae6f98c4651bd501597e6b52bc0.tar.bz2 rails-867dc1700f32aae6f98c4651bd501597e6b52bc0.zip |
Merge pull request #8156 from fredwu/acronym_fix-master
Fix for inflector's incorrect camelCase replacement for acronyms
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 2 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 9d26b8ba3e..331f6574ba 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -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* diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 39648727fd..648508d68e 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -91,7 +91,7 @@ module ActiveSupport 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') word.tr!("-", "_") word.downcase! diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 4806ce07f6..2b74055e68 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -167,11 +167,13 @@ class InflectorTest < ActiveSupport::TestCase def test_underscore_acronym_sequence ActiveSupport::Inflector.inflections do |inflect| inflect.acronym("API") + inflect.acronym("APIs") inflect.acronym("JSON") inflect.acronym("HTML") end assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI")) + assert_equal("namespaced/apis", ActiveSupport::Inflector.underscore("Namespaced::APIs")) end def test_underscore |