Skip to content

Commit

Permalink
Menu item should not match url if match_path is set
Browse files Browse the repository at this point in the history
The menu item should not match the url if a match_path prevents this behavior. Previously the match_path method went truthy, if the url of the menu item started with the same url as the request regardless of the given match_path - configuration.

(cherry picked from commit 26fa1c1)
  • Loading branch information
kulturbande committed Feb 8, 2024
1 parent b07a0a3 commit 2faadce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
23 changes: 11 additions & 12 deletions backend/lib/spree/backend_configuration/menu_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2faadce

Please sign in to comment.