Incorrect path parsing in app/assets/pages/projects/project.js clicked() function
Summary
In Repository -> Commits page, if a branch that is the same as the end of domain or group/user name or project name, a path
field is generated for /refs/switch request
Steps to reproduce
- create a branch that has the end of domain (for example: lab.com), group/user name (e.g. org) or project name (e.g. lab)
- Go to Repository -> Commits
- select a branch, created in step 1
- try to select any other branch
Example Project
https://gitlab.com/karolismc2/dotcom-branch-bug
What is the current bug behavior?
generated /refs/switch URL has additional path
field, which causes 404 error.
For example: When in https://gitlab.com/karolismc2/dotcom-branch-bug/-/commits/bug
, Swiching to com
branch, generates
https://gitlab.com/karolismc2/dotcom-branch-bug/-/refs/switch?utf8=%E2%9C%93&destination=commits&ref=com&path=-%2Fcommits%2F
request, which generates redirect to https://gitlab.com/karolismc2/dotcom-branch-bug/-/commits/com/-/commits/
, which shows 404 page
What is the expected correct behavior?
When in https://gitlab.com/karolismc2/dotcom-branch-bug/-/commits/bug
, Swiching to com
branch should generate request to
https://gitlab.com/karolismc2/dotcom-branch-bug/-/refs/switch?utf8=%E2%9C%93&destination=commits&ref=com
, which should genereate redirect to https://gitlab.com/karolismc2/dotcom-branch-bug/-/commits/com/
Relevant logs and/or screenshotsScreen_Recording_2021-05-14_at_01.39.11
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
I was able to track the problem to here: https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/pages/projects/project.js#L132
for splitPathAfterRefPortion
, loc
may need additional split operation.
const splitPathAfterRefPortion = loc.split('/-/')[1].split(currentRef)[1];