strip_attributes 1.14.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/strip_attributes/version.rb +1 -1
- data/lib/strip_attributes.rb +7 -4
- data/test/strip_attributes_test.rb +6 -4
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb6ecab9a2bccb06eeea8f6883037a3e1dbec6c5a84631cb06f48d5e77c2951
|
4
|
+
data.tar.gz: 1071d1c2da5993e200f0961f4fa34abaedea271e6a7609e7a0bb5ab7ff478500
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b97b24322b1f422a8c06380526323b27eaaf4aaf8da32679a06db83130c5042e0fc2054f9429c61739b536841c6829d3154755f6ba3d86d214d54ff76481f69b
|
7
|
+
data.tar.gz: ea18ab3064114407e588b3029a8e43ff87a3e3d7bccd50bfbea20d679198ceaf6586f59a64a265146aa0bc99e396ba44cf8f03b1cef619249b1369d87305caff
|
data/lib/strip_attributes.rb
CHANGED
@@ -27,8 +27,11 @@ module StripAttributes
|
|
27
27
|
# U+FEFF ZERO WIDTH NO-BREAK SPACE
|
28
28
|
MULTIBYTE_WHITE = "\u180E\u200B\u200C\u200D\u2060\uFEFF".freeze
|
29
29
|
MULTIBYTE_SPACE = /[[:space:]#{MULTIBYTE_WHITE}]/.freeze
|
30
|
+
MULTIBYTE_SPACE_AT_ENDS = /\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/.freeze
|
30
31
|
MULTIBYTE_BLANK = /[[:blank:]#{MULTIBYTE_WHITE}]/.freeze
|
32
|
+
MULTIBYTE_BLANK_REPEATED = /#{MULTIBYTE_BLANK}+/.freeze
|
31
33
|
MULTIBYTE_SUPPORTED = "\u0020" == " "
|
34
|
+
NEWLINES = /[\r\n]+/.freeze
|
32
35
|
|
33
36
|
def self.strip(record_or_string, options = {})
|
34
37
|
if record_or_string.respond_to?(:attributes)
|
@@ -52,26 +55,26 @@ module StripAttributes
|
|
52
55
|
|
53
56
|
def self.strip_string(value, options = {})
|
54
57
|
return value unless value.is_a?(String)
|
55
|
-
return value if value.frozen?
|
56
58
|
|
57
59
|
allow_empty = options[:allow_empty]
|
58
60
|
collapse_spaces = options[:collapse_spaces]
|
59
61
|
replace_newlines = options[:replace_newlines]
|
60
62
|
regex = options[:regex]
|
61
63
|
|
64
|
+
value = value.dup
|
62
65
|
value.gsub!(regex, "") if regex
|
63
66
|
|
64
67
|
if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_SPACE)
|
65
|
-
value.gsub!(
|
68
|
+
value.gsub!(MULTIBYTE_SPACE_AT_ENDS, "")
|
66
69
|
else
|
67
70
|
value.strip!
|
68
71
|
end
|
69
72
|
|
70
|
-
value.gsub!(
|
73
|
+
value.gsub!(NEWLINES, " ") if replace_newlines
|
71
74
|
|
72
75
|
if collapse_spaces
|
73
76
|
if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_BLANK)
|
74
|
-
value.gsub!(
|
77
|
+
value.gsub!(MULTIBYTE_BLANK_REPEATED, " ")
|
75
78
|
else
|
76
79
|
value.squeeze!(" ")
|
77
80
|
end
|
@@ -204,10 +204,12 @@ class StripAttributesTest < Minitest::Test
|
|
204
204
|
assert_equal "", record.bang
|
205
205
|
end
|
206
206
|
|
207
|
-
def
|
208
|
-
record = StripAllMockRecord.new(
|
207
|
+
def test_should_not_mutate_values
|
208
|
+
record = StripAllMockRecord.new(foo: " foo ")
|
209
|
+
old_value = record.foo
|
209
210
|
record.valid?
|
210
|
-
assert_equal "
|
211
|
+
assert_equal "foo", record.foo
|
212
|
+
refute_equal old_value, record.foo
|
211
213
|
end
|
212
214
|
|
213
215
|
def test_should_collapse_duplicate_spaces
|
@@ -428,7 +430,7 @@ class StripAttributesTest < Minitest::Test
|
|
428
430
|
skip "multi-byte characters not supported by this version of Ruby" unless StripAttributes::MULTIBYTE_SUPPORTED
|
429
431
|
|
430
432
|
assert_equal "foo", StripAttributes.strip("\u200A\u200B foo\u200A\u200B ")
|
431
|
-
assert_equal "foo\u20AC".
|
433
|
+
assert_equal "foo\u20AC".b, StripAttributes.strip("foo\u20AC ".b)
|
432
434
|
end
|
433
435
|
end
|
434
436
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strip_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan McGeary
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activemodel
|
@@ -128,7 +127,6 @@ metadata:
|
|
128
127
|
changelog_uri: https://github.com/rmm5t/strip_attributes/blob/master/CHANGELOG.md
|
129
128
|
source_code_uri: https://github.com/rmm5t/strip_attributes
|
130
129
|
funding_uri: https://github.com/sponsors/rmm5t
|
131
|
-
post_install_message:
|
132
130
|
rdoc_options: []
|
133
131
|
require_paths:
|
134
132
|
- lib
|
@@ -143,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
141
|
- !ruby/object:Gem::Version
|
144
142
|
version: '0'
|
145
143
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
144
|
+
rubygems_version: 3.6.3
|
148
145
|
specification_version: 4
|
149
146
|
summary: Whitespace cleanup for ActiveModel attributes
|
150
147
|
test_files:
|