Skip to content

Commit

Permalink
Merge pull request #5650 from solidusio/backport/v4.2/pr-5643
Browse files Browse the repository at this point in the history
[v4.2] Menu item should not match url if match_path is set
  • Loading branch information
tvdeyen committed Apr 5, 2024
2 parents 3ccc116 + 1c374d3 commit a6fca34
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 a6fca34

Please sign in to comment.