mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #14146 from chewi/fix-underscore-acronyms-regex
Fix underscore inflector handling of namespaced and adjacent acronyms
This commit is contained in:
commit
cf66278301
3 changed files with 8 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -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!("-", "_")
|
||||
|
|
|
@ -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"],
|
||||
|
|
Loading…
Reference in a new issue