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.

Fix Money#to_html sanitization

Damian Legawiec7c33ae11e907
diff --git a/backend/engines/core/lib/spree/money.rb b/backend/engines/core/lib/spree/money.rb
index 6a98741f53..8a1e7b24ef 100644
--- a/backend/engines/core/lib/spree/money.rb
+++ b/backend/engines/core/lib/spree/money.rb
@@ -51,17 +51,10 @@ module Spree
# 1) prevent blank, breaking spaces
# 2) prevent escaping of HTML character entities
def to_html(opts = { html: true })
- # html option is deprecated and we need to fallback to html_wrap
- opts[:html_wrap] = opts[:html]
opts.delete(:html)
- output = money.format(options.merge(opts))
- if opts[:html_wrap]
- output.gsub!(/<\/?[^>]*>/, '') # we don't want wrap every element in span
- output = output.sub(' ', '&nbsp;').html_safe
- end
-
- output
+ output = money.format(options.merge(opts).merge(html_wrap: false))
+ output.sub(' ', '&nbsp;').html_safe
end
def as_json(*)
diff --git a/backend/engines/core/spec/helpers/products_helper_spec.rb b/backend/engines/core/spec/helpers/products_helper_spec.rb
index fca81b12ee..b325fef730 100644
--- a/backend/engines/core/spec/helpers/products_helper_spec.rb
+++ b/backend/engines/core/spec/helpers/products_helper_spec.rb
@@ -61,13 +61,13 @@ module Spree
context 'when variant is more than master' do
let(:variant_price) { 150 }
- it { is_expected.to eq('(Add: &#x00A5;50)') }
+ it { is_expected.to eq("(Add: \u00A550)") }
end
context 'when variant is less than master' do
let(:product_price) { 150 }
- it { is_expected.to eq('(Subtract: &#x00A5;50)') }
+ it { is_expected.to eq("(Subtract: \u00A550)") }
end
end
end
@@ -104,7 +104,7 @@ module Spree
it 'returns the variant price if the price is different than master' do
product.price = 100
@variant1.price = 150
- expect(helper.variant_price(@variant1)).to eq('&#x00A5;150')
+ expect(helper.variant_price(@variant1)).to eq("\u00A5150")
end
end