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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Handle properly `Store#url` with port supplied (#12477)
Damian Legawiecd83288fd3c12
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex 557e9f9319..d8b0567475 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -266,20 +266,21 @@ module Spree@formatted_url ||= if Rails.env.development? || Rails.env.test?scheme = Rails.application.routes.default_url_options[:protocol] || :httpport = Rails.application.routes.default_url_options[:port].presence || (Rails.env.development? ? 3000 : nil)+ clean_url = url.to_s.sub(%r{^https?://}, '').split(':').firstif scheme.to_sym == :httpsURI::HTTPS.build(- host: url.to_s.sub(%r{^https?://}, ''),+ host: clean_url,port: port).to_selseURI::HTTP.build(- host: url.to_s.sub(%r{^https?://}, '').split(':').first,+ host: clean_url,port: port).to_sendelseURI::HTTPS.build(- host: url.to_s.sub(%r{^https?://}, '')+ host: clean_url).to_sendenddiff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rbindex ec4916f19a..b1c0533a40 100644--- a/core/spec/models/spree/store_spec.rb+++ b/core/spec/models/spree/store_spec.rb@@ -785,13 +785,19 @@ describe Spree::Store, type: :model doenddescribe '#formatted_url' do- let(:store) { create(:store, code: 'mystore', url: nil) }+ let(:store) { build(:store, code: 'mystore', url: 'mystore.mydomain.dev') }it { expect(store.formatted_url).to eq('http://mystore.mydomain.dev:3000') }++ context 'url with port' do+ let(:store) { build(:store, code: 'mystore', url: 'localhost:3000') }++ it { expect(store.formatted_url).to eq('http://localhost:3000') }+ endenddescribe '#formatted_url_or_custom_domain' do- let(:store) { create(:store, code: 'mystore', url: nil) }+ let(:store) { build(:store, code: 'mystore', url: 'mystore.mydomain.dev:3000') }context 'without custom domain' doit { expect(store.formatted_url_or_custom_domain).to eq('http://mystore.mydomain.dev:3000') }