Skip to content

Commit 2164d4f

Browse files
committed
Avoid regex backtracking in Inflector.underscore
[CVE-2023-22796]
1 parent cd46b0e commit 2164d4f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • activesupport/lib/active_support/inflector

activesupport/lib/active_support/inflector/methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def underscore(camel_cased_word)
9797
return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
9898
word = camel_cased_word.to_s.gsub("::", "/")
9999
word.gsub!(inflections.acronyms_underscore_regex) { "#{$1 && '_' }#{$2.downcase}" }
100-
word.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { ($1 || $2) << "_" }
100+
word.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { ($1 || $2) << "_" }
101101
word.tr!("-", "_")
102102
word.downcase!
103103
word

0 commit comments

Comments
 (0)