Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add auto_strip_attributes for sanitizing product properties values

Damian Legawiec208abf9dec81
diff --git a/core/app/models/spree/product_property.rb b/core/app/models/spree/product_property.rb
index 410caf54bb..3c0a019f69 100644
--- a/core/app/models/spree/product_property.rb
+++ b/core/app/models/spree/product_property.rb
@@ -1,5 +1,7 @@
module Spree
class ProductProperty < Spree::Base
+ auto_strip_attributes :value
+
acts_as_list scope: :product
with_options inverse_of: :product_properties do
@@ -17,8 +19,6 @@ module Spree
# virtual attributes for use with AJAX completion stuff
delegate :name, :presentation, to: :property, prefix: true, allow_nil: true
- before_save :trim_value, :set_param
-
def property_name=(name)
if name.present?
# don't use `find_by :name` to workaround globalize/globalize#423 bug
@@ -26,12 +26,6 @@ module Spree
end
end
- def trim_value
- return if value.blank?
-
- value.strip!
- end
-
def set_param
return if value.blank?
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb
index 486261cb7f..fd65376a3f 100644
--- a/core/lib/spree/core.rb
+++ b/core/lib/spree/core.rb
@@ -1,6 +1,7 @@
require 'rails/all'
require 'active_merchant'
require 'acts_as_list'
+require 'auto_strip_attributes'
require 'awesome_nested_set'
require 'cancan'
require 'friendly_id'
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 49f6804569..168af90e16 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activemerchant', '~> 1.67'
s.add_dependency 'acts_as_list', '>= 0.8', '< 2.0'
+ s.add_dependency 'auto_strip_attributes', '~> 2.6'
s.add_dependency 'awesome_nested_set', '>= 3.3.1', '< 4.0'
s.add_dependency 'carmen', '>= 1.0', '< 1.2'
s.add_dependency 'cancancan', '~> 3.2'