Fix 500 when creating a branch with an integer name

What does this MR do and why?

Problem

A JSON request with an integer branch name or ref reaches the sanitizer as an Integer and raises NoMethodError, returning 500.

Solution

  • Convert branch names and refs to strings before sanitizing.
  • Cover integer JSON params in controller specs.

References

No related issue exists. This change follows a Sentry error in rails/html/sanitizer.rb, triggered by Projects::BranchesController#create.

Screenshots or screen recordings

Not applicable. This change has no visual impact.

How to set up and validate locally

  1. Run bin/rspec spec/controllers/projects/branches_controller_spec.rb.
  2. Confirm the integer branch_name case returns 200 with the name "551", and the integer ref case creates the branch from an existing 551 ref (200).
  3. Confirm a missing branch name follows normal validation instead of returning 500.

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.

Edited by Vasilii Iakliushin

Merge request reports

Loading
Loading