Skip to content

Commit

Permalink
Merge branch 'master' into ruby_3_4
Browse files Browse the repository at this point in the history
  • Loading branch information
rmm5t authored Feb 24, 2025
2 parents 06ff2e7 + b7e052e commit 025988a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ["3.2", "3.3"]
ruby: ["3.2", "3.3", "3.4"]
gemfile:
- activemodel-7.1
- activemodel-7.2
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ Added multibyte whitespace support to `:collapse_spaces` option ([#32])

## [0.9.0] - untracked

[Unreleased]: https://github.com/rmm5t/strip_attributes/compare/v1.14.0..HEAD
[Unreleased]: https://github.com/rmm5t/strip_attributes/compare/v1.14.1..HEAD
[1.14.1]: https://github.com/rmm5t/strip_attributes/compare/v1.14.0..v1.14.1
[1.14.0]: https://github.com/rmm5t/strip_attributes/compare/v1.13.0..v1.14.0
[1.13.0]: https://github.com/rmm5t/strip_attributes/compare/v1.12.0..v1.13.0
[1.12.0]: https://github.com/rmm5t/strip_attributes/compare/v1.11.0..v1.12.0
Expand Down
10 changes: 7 additions & 3 deletions lib/strip_attributes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "active_model"

module ActiveModel::Validations::HelperMethods
Expand Down Expand Up @@ -27,8 +28,11 @@ module StripAttributes
# U+FEFF ZERO WIDTH NO-BREAK SPACE
MULTIBYTE_WHITE = "\u180E\u200B\u200C\u200D\u2060\uFEFF".freeze
MULTIBYTE_SPACE = /[[:space:]#{MULTIBYTE_WHITE}]/.freeze
MULTIBYTE_SPACE_AT_ENDS = /\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/.freeze
MULTIBYTE_BLANK = /[[:blank:]#{MULTIBYTE_WHITE}]/.freeze
MULTIBYTE_BLANK_REPEATED = /#{MULTIBYTE_BLANK}+/.freeze
MULTIBYTE_SUPPORTED = "\u0020" == " "
NEWLINES = /[\r\n]+/.freeze

def self.strip(record_or_string, options = {})
if record_or_string.respond_to?(:attributes)
Expand Down Expand Up @@ -62,16 +66,16 @@ def self.strip_string(value, options = {})
value = value.gsub(regex, "") if regex

value = if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_SPACE)
value.gsub(/\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/, "")
value.gsub(MULTIBYTE_SPACE_AT_ENDS, "")
else
value.strip
end

value = value.gsub(/[\r\n]+/, " ") if replace_newlines
value = value.gsub(NEWLINES, " ") if replace_newlines

if collapse_spaces
value = if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_BLANK)
value.gsub(/#{MULTIBYTE_BLANK}+/, " ")
value.gsub(MULTIBYTE_BLANK_REPEATED, " ")
else
value.squeeze(" ")
end
Expand Down
3 changes: 2 additions & 1 deletion strip_attributes.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "strip_attributes/version"
Expand Down Expand Up @@ -32,5 +33,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest-reporters", ">= 0.14.24"
spec.add_development_dependency "rake"

spec.required_ruby_version = '>= 1.9.3'
spec.required_ruby_version = ">= 1.9.3"
end

0 comments on commit 025988a

Please sign in to comment.