Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…isregarding specified acronyms, fixes #8015
  • Loading branch information...
commit 515feb1fd61184cb14840a8f3b82ba3c388fdc3c 1 parent 9a421aa
Fred Wu fredwu authored
2  activesupport/lib/active_support/inflector/methods.rb
View
@@ -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')
word.tr!("-", "_")
word.downcase!
2  activesupport/test/inflector_test.rb
View
@@ -167,11 +167,13 @@ def test_acronyms_camelize_lower
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
Please sign in to comment.
Something went wrong with that request. Please try again.