diff --git a/backend/lib/spree/backend_configuration/menu_item.rb b/backend/lib/spree/backend_configuration/menu_item.rb index 9ba33cef66a..76f0fe5060b 100644 --- a/backend/lib/spree/backend_configuration/menu_item.rb +++ b/backend/lib/spree/backend_configuration/menu_item.rb @@ -78,18 +78,17 @@ def render_partial? end def match_path?(request) - matches = - if match_path.is_a? Regexp - request.fullpath =~ match_path - elsif match_path.respond_to?(:call) - match_path.call(request) - elsif match_path - request.fullpath.starts_with?("#{spree.admin_path}#{match_path}") - end - matches ||= request.fullpath.to_s.starts_with?(url.to_s) if url.present? - matches ||= @sections.include?(request.controller_class.controller_name.to_sym) if @sections.present? - - matches + if match_path.is_a? Regexp + request.fullpath =~ match_path + elsif match_path.respond_to?(:call) + match_path.call(request) + elsif match_path + request.fullpath.starts_with?("#{spree.admin_path}#{match_path}") + elsif url.present? + request.fullpath.to_s.starts_with?(url.to_s) + elsif @sections.present? + @sections.include?(request.controller_class.controller_name.to_sym) + end end def url diff --git a/backend/spec/lib/spree/backend_configuration/menu_item_spec.rb b/backend/spec/lib/spree/backend_configuration/menu_item_spec.rb index 17100be1212..c65e08b5545 100644 --- a/backend/spec/lib/spree/backend_configuration/menu_item_spec.rb +++ b/backend/spec/lib/spree/backend_configuration/menu_item_spec.rb @@ -59,6 +59,13 @@ expect(subject.match_path?(matching_request)).to be true expect(subject.match_path?(other_request)).to be false end + + it 'should not match the url if a match_path is set' do + subject = described_class.new(match_path: %r{/url$/}, url: "/foo/url") + request = double(ActionDispatch::Request, fullpath: '/foo/url_which_starts_with_the_same_characters') + + expect(subject.match_path?(request)).to be_falsey + end end describe "#url" do