Redirect case sensitive project path to the normalized one

This commit is contained in:
Francesco Levorato 2015-09-17 15:56:16 +02:00
parent 6bff207dfd
commit 1bbcc29687
3 changed files with 26 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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