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.txt Screen_Recording_2025-11-25_at_10.52.13_PM

After

How to set up and validate locally

  1. Create a new branch with a # character in the name:
    git checkout -b 'issues/#101'

``

  1. 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'

  2. Navigate to Repository > Files in the GitLab UI

  3. Switch to the issues/#101 branch

  4. Click on Text.txt in the file list

    • Expected: File preview loads correctly
  5. Reload the page (F5)

    • Before fix: File preview breaks, shows error or blank page
    • After fix: File preview continues to work correctly
  6. Check the browser URL bar:

    • Expected: /-/blob/issues/%23101/Text.txt (with # encoded as %23)
  7. Test navigation:

    • Navigate back to tree view (/-/tree/issues/%23101)
    • Reload the page
    • Expected: Directory listing loads correctly
  8. Test with other special characters:

    • Create branches like feat#test, bug#fix
    • Verify file preview and tree view work on reload for all

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.

Closes #579389 Related to !213677 (merged)

Edited by Joseph Fletcher

Merge request reports

Loading