Commit a60f6aa7 authored by Stan Hu's avatar Stan Hu

Merge branch '18292-project-name-to-path-conversion-in-api-mangles-dots' into 'master'

Resolve "Project name to path conversion in API mangles dots"

See merge request gitlab-org/gitlab!52725
parents 6355f9c0 018dcf92
......@@ -210,16 +210,22 @@ module Projects
end
def set_project_name_from_path
# Set project name from path
if @project.name.present? && @project.path.present?
# if both name and path set - everything is ok
elsif @project.path.present?
# if both name and path set - everything is ok
return if @project.name.present? && @project.path.present?
if @project.path.present?
# Set project name from path
@project.name = @project.path.dup
elsif @project.name.present?
# For compatibility - set path from name
# TODO: remove this in 8.0
@project.path = @project.name.dup.parameterize
@project.path = @project.name.dup
# TODO: Retained for backwards compatibility. Remove in API v5.
# When removed, validation errors will get bubbled up automatically.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52725
unless @project.path.match?(Gitlab::PathRegex.project_path_format_regex)
@project.path = @project.path.parameterize
end
end
end
......
---
title: "API: do not mangle dots when creating project with a name"
merge_request: 52725
author:
type: fixed
......@@ -40,6 +40,48 @@ RSpec.describe Projects::CreateService, '#execute' do
end
end
describe 'setting name and path' do
subject(:project) { create_project(user, opts) }
context 'when both are set' do
let(:opts) { { name: 'one', path: 'two' } }
it 'keeps them as specified' do
expect(project.name).to eq('one')
expect(project.path).to eq('two')
end
end
context 'when path is set' do
let(:opts) { { path: 'one.two_three-four' } }
it 'sets name == path' do
expect(project.path).to eq('one.two_three-four')
expect(project.name).to eq(project.path)
end
end
context 'when name is a valid path' do
let(:opts) { { name: 'one.two_three-four' } }
it 'sets path == name' do
expect(project.name).to eq('one.two_three-four')
expect(project.path).to eq(project.name)
end
end
context 'when name is not a valid path' do
let(:opts) { { name: 'one.two_three-four and five' } }
# TODO: Retained for backwards compatibility. Remove in API v5.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52725
it 'parameterizes the name' do
expect(project.name).to eq('one.two_three-four and five')
expect(project.path).to eq('one-two_three-four-and-five')
end
end
end
context 'user namespace' do
it do
project = create_project(user, opts)
......@@ -419,7 +461,7 @@ RSpec.describe Projects::CreateService, '#execute' do
context 'when another repository already exists on disk' do
let(:opts) do
{
name: 'Existing',
name: 'existing',
namespace_id: user.namespace.id
}
end
......
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