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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d901257abbca144b30becb86cd248e512f8f8b140a6f822d3965f1896356d7c
4
- data.tar.gz: 798c083261f25f554767c216cfb399961e48e723a5d06355a12f82cb591eed45
3
+ metadata.gz: fbb6ecab9a2bccb06eeea8f6883037a3e1dbec6c5a84631cb06f48d5e77c2951
4
+ data.tar.gz: 1071d1c2da5993e200f0961f4fa34abaedea271e6a7609e7a0bb5ab7ff478500
5
5
  SHA512:
6
- metadata.gz: 01a7956efa14fa00820e59171bbc1324d015a457db4224f1d5903d1c9ecce31b39d2cc9fb34c26a7e9ae2dcf868fc49034682d5d2f6a0bb532ab89c16898a938
7
- data.tar.gz: 41ac5050c3810cd7de390efff4564a6cec3b025fc90455ce3b6c084444821a3deeb4873155b4ee00cc86f9dfaa426a31f88d1aeaca8195ee0965c606ea56d04b
6
+ metadata.gz: b97b24322b1f422a8c06380526323b27eaaf4aaf8da32679a06db83130c5042e0fc2054f9429c61739b536841c6829d3154755f6ba3d86d214d54ff76481f69b
7
+ data.tar.gz: ea18ab3064114407e588b3029a8e43ff87a3e3d7bccd50bfbea20d679198ceaf6586f59a64a265146aa0bc99e396ba44cf8f03b1cef619249b1369d87305caff
@@ -1,3 +1,3 @@
1
1
  module StripAttributes
2
- VERSION = "1.14.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -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!(/\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/, "")
68
+ value.gsub!(MULTIBYTE_SPACE_AT_ENDS, "")
66
69
  else
67
70
  value.strip!
68
71
  end
69
72
 
70
- value.gsub!(/[\r\n]+/, " ") if replace_newlines
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!(/#{MULTIBYTE_BLANK}+/, " ")
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 test_should_skip_frozen_values
208
- record = StripAllMockRecord.new(frozen: " ice ".freeze)
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 " ice ", record.frozen
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".force_encoding("ASCII-8BIT"), StripAttributes.strip("foo\u20AC ".force_encoding("ASCII-8BIT"))
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: 1.14.1
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: 2024-12-10 00:00:00.000000000 Z
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.5.23
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: