diff options
author | Matthew Draper <matthew@trebex.net> | 2014-10-04 08:15:41 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-10-04 08:16:55 +0930 |
commit | cf662783016462ce03ffbf76d09ad826ef5242ba (patch) | |
tree | b07878b13c05d2a13bae6439f7a9db238eecc171 /activesupport | |
parent | 657ce17868b0eba89680b8e215fded0e3d53a685 (diff) | |
parent | 6a8464fa4f50a0fce3ce245f717b813712ea27a8 (diff) | |
download | rails-cf662783016462ce03ffbf76d09ad826ef5242ba.tar.gz rails-cf662783016462ce03ffbf76d09ad826ef5242ba.tar.bz2 rails-cf662783016462ce03ffbf76d09ad826ef5242ba.zip |
Merge pull request #14146 from chewi/fix-underscore-acronyms-regex
Fix underscore inflector handling of namespaced and adjacent 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 | 3 |
3 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index a5fe6d65d9..74d57180fe 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 f35e71ce81..5b75dd65d0 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -91,7 +91,7 @@ module ActiveSupport 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 b37f31bc5f..5446c5ec3c 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -125,6 +125,9 @@ class InflectorTest < ActiveSupport::TestCase ["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"], |