|
1 |
| -# frozen_string_literal: true |
2 | 1 | require "active_model"
|
3 | 2 |
|
4 | 3 | module ActiveModel::Validations::HelperMethods
|
@@ -56,28 +55,28 @@ def self.strip_record(record, options = {})
|
56 | 55 |
|
57 | 56 | def self.strip_string(value, options = {})
|
58 | 57 | return value unless value.is_a?(String)
|
59 |
| - value = value.dup |
60 | 58 |
|
61 | 59 | allow_empty = options[:allow_empty]
|
62 | 60 | collapse_spaces = options[:collapse_spaces]
|
63 | 61 | replace_newlines = options[:replace_newlines]
|
64 | 62 | regex = options[:regex]
|
65 | 63 |
|
66 |
| - value = value.gsub(regex, "") if regex |
| 64 | + value = value.dup |
| 65 | + value.gsub!(regex, "") if regex |
67 | 66 |
|
68 |
| - value = if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_SPACE) |
69 |
| - value.gsub(MULTIBYTE_SPACE_AT_ENDS, "") |
| 67 | + if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_SPACE) |
| 68 | + value.gsub!(MULTIBYTE_SPACE_AT_ENDS, "") |
70 | 69 | else
|
71 |
| - value.strip |
| 70 | + value.strip! |
72 | 71 | end
|
73 | 72 |
|
74 |
| - value = value.gsub(NEWLINES, " ") if replace_newlines |
| 73 | + value.gsub!(NEWLINES, " ") if replace_newlines |
75 | 74 |
|
76 | 75 | if collapse_spaces
|
77 |
| - value = if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_BLANK) |
78 |
| - value.gsub(MULTIBYTE_BLANK_REPEATED, " ") |
| 76 | + if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_BLANK) |
| 77 | + value.gsub!(MULTIBYTE_BLANK_REPEATED, " ") |
79 | 78 | else
|
80 |
| - value.squeeze(" ") |
| 79 | + value.squeeze!(" ") |
81 | 80 | end
|
82 | 81 | end
|
83 | 82 |
|
|
0 commit comments