Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu item should not match url if match_path is set #5643

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 90 in backend/lib/spree/backend_configuration/menu_item.rb

View check run for this annotation

Codecov / codecov/patch

backend/lib/spree/backend_configuration/menu_item.rb#L81-L90

Added lines #L81 - L90 were not covered by tests
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
Loading