Enforce branch encoding
What does this MR do and why?
Fixes branch names with special characters (particularly #) breaking file preview on page reload.
When a branch name contains a # character (e.g., issues/#101), the file preview works on initial navigation but breaks when the page is reloaded. This happens because the # character is interpreted by the browser as a URL fragment identifier instead of being part of the branch name, causing everything after the # to be lost.
This MR ensures branch names are properly URL-encoded when initializing the Vue Router in both the tree view and blob view entry points, preventing the browser from misinterpreting special characters.
Screenshots or screen recordings
Before
- Navigate to a file on branch
issues/#101→✅ Works - Reload the page (F5) →
❌ File preview breaks, shows blank page - Browser interprets URL as:
/-/blob/issues/+ fragment#101/Text.txtScreen_Recording_2025-11-25_at_10.52.13_PM
After
- Navigate to a file on branch
issues/#101→✅ Works - Reload the page (F5) →
✅ Still works - URL correctly shows:
/-/blob/issues/%23101/Text.txtScreen_Recording_2025-11-25_at_10.51.09_PM
How to set up and validate locally
- Create a new branch with a
#character in the name:git checkout -b 'issues/#101'
``
-
Create a test file in this branch:
echo "Test content" > Text.txt git add Text.txt git commit -m "Add test file" git push origin 'issues/#101' -
Navigate to Repository > Files in the GitLab UI
-
Switch to the
issues/#101branch -
Click on
Text.txtin the file list- Expected: File preview loads correctly
-
Reload the page (F5)
- Before fix: File preview breaks, shows error or blank page
- After fix: File preview continues to work correctly
-
Check the browser URL bar:
-
Expected:
/-/blob/issues/%23101/Text.txt(with#encoded as%23)
-
Expected:
-
Test navigation:
- Navigate back to tree view (
/-/tree/issues/%23101) - Reload the page
- Expected: Directory listing loads correctly
- Navigate back to tree view (
-
Test with other special characters:
- Create branches like
feat#test,bug#fix - Verify file preview and tree view work on reload for all
- Create branches like
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
-
This MR is added to the appropriate milestone -
This MR includes changelog entry or does not require one -
This MR has a severity labelassigned -
This MR has a type labelassigned -
This MR has documentation if it is introducing or changing behavior -
This MR has tests added or updated -
This MR follows the code review guidelines -
This MR follows the merge request performance guidelines -
This MR follows the style guides
Related issues
Closes #579389 Related to !213677 (merged)