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 custom_domain to accept composed TLDs e.g: .com.br (#12946)

Neri J. Jakubowski Jr.ea2516f25a44
diff --git a/core/app/models/spree/custom_domain.rb b/core/app/models/spree/custom_domain.rb
index 3af4720da2..38b67dafef 100644
--- a/core/app/models/spree/custom_domain.rb
+++ b/core/app/models/spree/custom_domain.rb
@@ -29,7 +29,7 @@ module Spree
return if url.blank?
parts = url.split('.')
- errors.add(:url, 'use domain or subdomain') if (parts[0] != 'www' && parts.size > 3) || (parts[0] == 'www' && parts.size > 4) || parts.size < 2
+ errors.add(:url, 'use domain or subdomain') if parts.size > 4 || parts.size < 2
end
def ensure_default
diff --git a/core/spec/models/spree/custom_domain_spec.rb b/core/spec/models/spree/custom_domain_spec.rb
index 0206d99421..c8e989b75b 100644
--- a/core/spec/models/spree/custom_domain_spec.rb
+++ b/core/spec/models/spree/custom_domain_spec.rb
@@ -18,6 +18,10 @@ RSpec.describe Spree::CustomDomain, type: :model do
expect(build(:custom_domain, url: 'shop.custom.domain')).to be_valid
end
+ it 'is valid with composed tlds' do
+ expect(build(:custom_domain, url: 'shop.domain.com.br')).to be_valid
+ end
+
it 'is invalid with wrong number of parts' do
expect(build(:custom_domain, url: 'com')).not_to be_valid
end