1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #8156 from fredwu/acronym_fix-master

Fix for inflector's incorrect camelCase replacement for acronyms
This commit is contained in:
Xavier Noria 2013-03-16 07:59:47 -07:00
commit 867dc1700f
3 changed files with 7 additions and 1 deletions

View file

@ -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*

View file

@ -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!

View file

@ -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