aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorFred Wu <ifredwu@gmail.com>2012-11-09 22:09:01 +1100
committerFred Wu <ifredwu@gmail.com>2013-03-17 00:31:00 +1100
commit515feb1fd61184cb14840a8f3b82ba3c388fdc3c (patch)
tree7600a0a2b1021918da6c3a55178fe6f802e88e8f /activesupport
parent9a421aaa8285cf2a7ecb1af370748b0337818930 (diff)
downloadrails-515feb1fd61184cb14840a8f3b82ba3c388fdc3c.tar.gz
rails-515feb1fd61184cb14840a8f3b82ba3c388fdc3c.tar.bz2
rails-515feb1fd61184cb14840a8f3b82ba3c388fdc3c.zip
Fixed a bug where the inflector would replace camelCase strings and disregarding specified acronyms, fixes #8015
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb2
-rw-r--r--activesupport/test/inflector_test.rb2
2 files changed, 3 insertions, 1 deletions
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