Commit 1bbcc296 authored by Francesco Levorato's avatar Francesco Levorato

Redirect case sensitive project path to the normalized one

parent 6bff207d
......@@ -117,9 +117,14 @@ class ApplicationController < ActionController::Base
redirect_to request.original_url.gsub(/\.git\Z/, '') and return
end
@project = Project.find_with_namespace("#{namespace}/#{id}")
project_path = "#{namespace}/#{id}"
@project = Project.find_with_namespace(project_path)
if @project and can?(current_user, :read_project, @project)
if @project.path_with_namespace != project_path
redirect_to request.original_url.gsub(project_path, @project.path_with_namespace) and return
end
@project
elsif current_user.nil?
@project = nil
......
......@@ -17,6 +17,12 @@ describe Projects::IssuesController do
expect(response.status).to eq(200)
end
it "return 301 if request path doesn't match project path" do
get :index, namespace_id: project.namespace.path, project_id: project.path.upcase
expect(response).to redirect_to(namespace_project_issues_path(project.namespace, project))
end
it "returns 404 when issues are disabled" do
project.issues_enabled = false
project.save
......
......@@ -21,6 +21,20 @@ describe ProjectsController do
expect(response.body).to include("content='#{content}'")
end
end
context "when requested with case sensitive namespace and project path" do
it "redirects to the normalized path for case mismatch" do
get :show, namespace_id: public_project.namespace.path, id: public_project.path.upcase
expect(response).to redirect_to("/#{public_project.path_with_namespace}")
end
it "loads the page if normalized path matches request path" do
get :show, namespace_id: public_project.namespace.path, id: public_project.path
expect(response.status).to eq(200)
end
end
end
describe "POST #toggle_star" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment