Wrong Urlencoding when Switching Branch in Commit View

Summary

I have a branch called "ZubehörkartonEtiketten" in my project.
When in Commits-View on master ( /commits/master ) an selecting the branch "ZubehörkartonEtiketten" Gitlab fails with error 500, because the url uses the wrong encoding (utf16 I guess?!):
/refs/switch?utf8=✓&destination=commits&ref=Zubeh%25F6rkartonEtiketten

The correct encoding (utf8) would be:
/refs/switch?utf8=✓&destination=commits&ref=Zubeh%c3%b6rkartonEtiketten

If I change the url manually to the correct encoding, I'm redirected to the correct page. (commit view on branch "ZubehörkartonEtiketten")

Steps To Reproduce

  1. Create a new project
  2. Create a new branch called "ZubehörkartonEtiketten"
  3. Navigate to the "Commits" view for the new project
  4. Select "ZubehörkartonEtiketten" branch from the drop down branch selector

Expected Results

Redirected to commits view for selected branch

Actual Results

500 error results

Additional Detail

GitLab.com Project exhibiting this behaviour: https://gitlab.com/markglenfletcher/test-branch-names-with-spec-chars/commits/master#

The following line escapes the special characters: https://gitlab.com/gitlab-org/gitlab-ce/blob/0f4ff69fb4a88b0d98105c60c653abb3c587cb65/app/assets/javascripts/project.js#L82

Reproducing locally and catching the 500 error:

>> id
=> "Zubeh\xF6rkartonEtiketten"
>> id.match(/^([[:alnum:]]{40})(.+)/)
!! #<ArgumentError: invalid byte sequence in UTF-8>

Raised at the following line: https://gitlab.com/gitlab-org/gitlab-ce/blob/0f4ff69fb4a88b0d98105c60c653abb3c587cb65/lib/extracts_path.rb