Fix a double-slash URL problem when MR URL ends with a trailing slash
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA
What does this MR do and why?
As described in #462210 (closed), when we change tabs of a merge request page whose URL ends with a trailing slash, the URL changes to double-slash like below.
- Open
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/153330/
- Click
Changes
tab. - URL changes to
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/153330//diffs
<= double-slash
This MR fixes it like below.
- Open
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/153330/
- Click
Changes
tab. - URL changes to
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/153330/diffs
. <= no double-slash
The reason why I don't remove the trailing slash of Overview
tab:
I checked how the trailing slash of other tabs was removed. For example, when I open Changes
tab with a trailing slash, the URL .../diffs/
changed to .../diffs
automatically.
It occurred due to https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/merge_request_tabs.js#L447.
Because each variable is below, and these are not same.
window.location.pathname = /flightjs/Flight/-/merge_requests/4/diffs/
newState = /flightjs/Flight/-/merge_requests/4/diffs
This works like the tab is changed, and this is not a correct behavior. I don't think the trailing slash is a problem of each tab. The problem is a double-slash after changing tabs. So I added code to remove the trailing slash before handling tab actions.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
Screen_Recording_2024-08-18_at_14.59.05 | Screen_Recording_2024-08-18_at_14.58.24 |
How to set up and validate locally
- Run gdk, and sign in to http://gdk.local:3000.
- Open http://gdk.local:3000/flightjs/Flight/-/merge_requests/4/.
Overview
tab is shown. - Click
Changes
tab. - Check the URL is http://gdk.local:3000/flightjs/Flight/-/merge_requests/4/diffs. (no double-slash)
Related to #462210 (closed)