Can’t use consecutive minus sign / dash in project’s slug
Summary
I can’t create a project on GitLab.com if the project’s slug contains two (or more) consecutive -
(minus sign / dash).
Steps to reproduce
- Go to https://gitlab.com/projects/new#blank_project
- Fill the form as follows:
- Project name :
Test
- Project URL:
https://gitlab.com/SOME_USERNAME/
(it’s an example) - Project slug:
foo--bar--qux
- Validate using the “Create project” button
What is the current bug behavior?
- The previous form is shown again, still filled with my inputs.
- There is the following error message:
The form contains the following errors:
- Project namespace path can only include non-accented letters, digits, ‘', ‘-’ and ‘.’. It must not start with ‘-’, '’, or ‘.’, nor end with ‘-’, ‘_’, ‘.’, ‘.git’, or ‘.atom’.
- Path can only include non-accented letters, digits, ‘', ‘-’ and ‘.’. It must not start with ‘-’, '’, or ‘.’, nor end with ‘-’, ‘_’, ‘.’, ‘.git’, or ‘.atom’.
What is the expected correct behavior?
Projet "Test" should be created at: https://gitlab.com/SOME_USERNAME/foo--bar--qux
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
GitLab Enterprise Edition 17.11.0-pre 8aa6ee30e90
Possible fixes
I think the responsible code is https://gitlab.com/gitlab-org/gitlab/-/blob/f2d807cba4bca3e692f9cf578e7c87689ec360cc/lib/gitlab/regex.rb#L21-24:
# Project path must conform to this regex. See https://gitlab.com/gitlab-org/gitlab/-/issues/27483
def oci_repository_path_regex
@oci_repository_path_regex ||= %r{\A[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*\z}
end
I am not really sure if the [a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*
regex is compliant with #27483 where it is stated:
There is nothing we can do about supporting leading or trailing underscores in container repository paths. Repository paths must conform to the
[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*
regexp defined upstream in the OCI Distribution specification (link).
As the OCI Distribution specification says the regex is [a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(\/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*
.
Anyway, the OCI Distribution specification accepts foo--bar--qux
but both #27483 and oci_repository_path_regex
don't:
Regex Source | Pass? | Example |
---|---|---|
OCI Distribution specification | regex101 | |
Issue #27483 | regex101 | |
oci_repository_path_regex method |
regex101 |
Other notes
I've posted this finding in the forum prior to opening an issue: https://forum.gitlab.com/t/cant-use-minus-sign-dash-in-projects-slug/123219.