diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index a5fe6d65d9c122ffe147067e849a950773b594d5..74d57180fe935727553fc735545b90fbfbc35c29 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,7 @@ +* Corrected Inflector#underscore handling of multiple successive acroynms. + + *James Le Cuirot* + * Delegation now works with ruby reserved words passed to `:to` option. Fixes #16956. diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index f35e71ce8115950e912b6ed856688c07aaa1c3d1..5b75dd65d036027cbeed78d2e144f4bfbf44208b 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -91,7 +91,7 @@ def camelize(term, uppercase_first_letter = true) def underscore(camel_cased_word) return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ word = camel_cased_word.to_s.gsub('::', '/') - word.gsub!(/(?:([A-Za-z\d])|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" } + word.gsub!(/(?<=([A-Za-z\d])|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index b37f31bc5f0a5450320dc27ebb01b63e04c17446..5446c5ec3c5aa474cba41cab2cbcaba381cdb8c8 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -125,6 +125,9 @@ def test_acronyms ["PhDRequired", "phd_required", "PhD required", "PhD Required"], ["IRoRU", "i_ror_u", "I RoR u", "I RoR U"], ["RESTfulHTTPAPI", "restful_http_api", "RESTful HTTP API", "RESTful HTTP API"], + ["HTTP::RESTful", "http/restful", "HTTP/RESTful", "HTTP/RESTful"], + ["HTTP::RESTfulAPI", "http/restful_api", "HTTP/RESTful API", "HTTP/RESTful API"], + ["APIRESTful", "api_restful", "API RESTful", "API RESTful"], # misdirection ["Capistrano", "capistrano", "Capistrano", "Capistrano"],