Bug: GitLab searches fails when the branch name includes the "+" character

Summary

A US Government customer raised an issue that when reviewing the results from global search, switching to a branch that includes + returns We couldn't find any projects matching <search-term>.

Relevant info:

Steps to reproduce

In my example project:

  1. Create a branch with +, for example: main+testing
  2. Search for a unique term -- for example: Bibliotaph
  3. In the search results, switch to the main+testing branch

Example Project

https://gitlab.com/dcoy/6742-weird-branch-issue

What is the current bug behavior?

Switching to branches that include + in search returns We couldn't find any projects matching <search-term>.

What is the expected correct behavior?

Switching branches that include + should display the results if the search term is found.

Relevant logs and/or screenshots

{
  "component": "gitlab",
  "subcomponent": "production_json",
  "method": "GET",
  "path": "/search/count",
  "format": "json",
  "controller": "SearchController",
  "action": "count",
  "status": 200,
  "time": "2023-11-02T18:07:16.598Z",
  "params": [
    {
      "key": "project_id",
      "value": "8"
    },
    {
      "key": "repository_ref",
      "value": "main+testing"
    },
    {
      "key": "scope",
      "value": "milestones"
    },
    {
      "key": "search",
      "value": "[FILTERED]"
    }
  ],
  "correlation_id": "01HE8KFMJSAEPC6Z91NNYG5X0Q",
  "meta.caller_id": "SearchController#count",
  "meta.remote_ip": "[REDACTED]",
  "meta.feature_category": "global_search",
  "meta.user": "dcoy",
  "meta.user_id": 4,
  "meta.client_id": "user/4",
  "meta.search.group_id": null,
  "meta.search.project_id": "8",
  "meta.search.scope": "milestones",
  "meta.search.filters.confidential": null,
  "meta.search.filters.state": null,
  "meta.search.force_search_results": null,
  "meta.search.project_ids": null,
  "meta.search.filters.language": null,
  "abuse.confidence": 1,
  "abuse.messages": [
    "Repository ref abusive characters detected"
  ],
  "remote_ip": "[REDACTED]",
  "user_id": 4,
  "username": "dcoy",
  "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
  "queue_duration_s": 0.00764,
  [...]
  "rate_limiting_gates": [
    "search_rate_limit"
  ],
}

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info
kubectl exec -it gl-dcoy-toolbox-77c7f7bdfb-hx4qx -- gitlab-rake gitlab:env:info
Defaulted container "toolbox" out of: toolbox, certificates (init), configure (init)

System information
System:
Proxy:		no
Current User:	git
Using RVM:	no
Ruby Version:	3.0.6p216
Gem Version:	3.4.20
Bundler Version:2.4.20
Rake Version:	13.0.6
Redis Version:	6.0.16
Sidekiq Version:6.5.7
Go Version:	unknown

GitLab information
Version:	16.5.0-ee
Revision:	fc87c9d4cca
Directory:	/srv/gitlab
DB Adapter:	PostgreSQL
DB Version:	14.8
URL:		https://[REDACTED]
HTTP Clone URL:	https://[REDACTED]/some-group/some-project.git
SSH Clone URL:	git@[REDACTED]:some-group/some-project.git
Elasticsearch:	no
Geo:		no
Using LDAP:	no
Using Omniauth:	yes
Omniauth Providers: gitlab

GitLab Shell
Version:	14.29.0
Repository storages:
- default: 	tcp://gl-dcoy-gitaly-0.gl-dcoy-gitaly.default.svc:8075
GitLab Shell path:		/home/git/gitlab-shell

Gitaly
- default Address: 	tcp://gl-dcoy-gitaly-0.gl-dcoy-gitaly.default.svc:8075
- default Version: 	16.5.0
- default Git Version: 	2.42.0

Results of GitLab application Check

Expand for output related to the GitLab application check

kubectl exec -it gl-dcoy-toolbox-77c7f7bdfb-hx4qx -- gitlab-rake gitlab:check SANITIZE=true Defaulted container "toolbox" out of: toolbox, certificates (init), configure (init) Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 14.29.0 ? ... OK (14.29.0) Running /home/git/gitlab-shell/bin/check gitlab-shell self-check failed Try fixing it: Make sure GitLab is running; Check the gitlab-shell configuration file: sudo -u git -H editor /home/git/gitlab-shell/config.yml Please fix the error above and rerun the checks.

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... no Try fixing it: sudo -u git -H RAILS_ENV=production bin/background_jobs start For more information see: doc/install/installation.md in section "Install Init Script" see log/sidekiq.log for possible errors Please fix the error above and rerun the checks.

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet) Systemd unit files or init script exist? ... no Try fixing it: Install the Service For more information see: doc/install/installation.md in section "Install the Service" Please fix the error above and rerun the checks. Systemd unit files or init script up-to-date? ... can't check because of previous errors Projects have namespace: ... 1/1 ... yes 5/2 ... yes 5/3 ... yes 5/4 ... yes 5/5 ... yes 5/6 ... yes 5/7 ... yes 5/8 ... yes 14/9 ... yes 14/10 ... yes 14/11 ... yes 14/13 ... yes 14/14 ... yes 26/15 ... yes 26/16 ... yes 14/17 ... yes 14/18 ... yes 14/19 ... yes 34/20 ... yes 14/21 ... yes 14/22 ... yes Redis version >= 6.0.0? ... yes Ruby version >= 3.0.6 ? ... yes (3.0.6) Git user has default SSH configuration? ... yes Active users: ... 7 Is authorized keys file accessible? ... skipped (authorized keys not enabled) GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-8.x or OpenSearch version 1.x ... skipped (Advanced Search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Possible fixes