Environment with starting slash in name causes error

Summary

Creating an environment with a name beginning with a slash causes error

Description

https://sentry.gitlap.com/gitlab/gitlabcom/issues/109166/

ActionController::UrlGenerationError: No route matches {:action=>"folder", :controller=>"projects/environments", :id=>"", :namespace_id=>#<Group id:785414 @issue-reproduce>, :project_id=>#<Project id:4588064 issue-reproduce/borken-environments-list>} missing required keys: [:id]
  from action_dispatch/journey/formatter.rb:46:in `generate'
  from action_dispatch/routing/route_set.rb:721:in `generate'
  from action_dispatch/routing/route_set.rb:752:in `generate'
  from action_dispatch/routing/route_set.rb:799:in `url_for'
  from action_dispatch/routing/route_set.rb:280:in `call'
  from action_dispatch/routing/route_set.rb:345:in `block (2 levels) in define_url_helper'
  from config/application.rb:195:in `block (4 levels) in <class:Application>'
  from app/serializers/environment_entity.rb:32:in `block in <class:EnvironmentEntity>'
  from grape_entity/entity.rb:475:in `instance_exec'
  from grape_entity/entity.rb:475:in `exec_with_object'
  from grape_entity/exposure/block_exposure.rb:8:in `value'
  from grape_entity/exposure/base.rb:79:in `valid_value'
  from grape_entity/exposure/base.rb:63:in `serializable_value'
  from grape_entity/exposure/nesting_exposure.rb:61:in `block (2 levels) in serializable_value'
  from grape_entity/exposure/base.rb:109:in `block in with_attr_path'
  from grape_entity/options.rb:102:in `with_attr_path'
  from grape_entity/exposure/base.rb:108:in `with_attr_path'
  from grape_entity/exposure/nesting_exposure.rb:60:in `block in serializable_value'
  from grape_entity/exposure/nesting_exposure.rb:59:in `each'
  from grape_entity/exposure/nesting_exposure.rb:59:in `each_with_object'
  from grape_entity/exposure/nesting_exposure.rb:59:in `serializable_value'
  from grape_entity/entity.rb:471:in `serializable_hash'
  from app/serializers/base_serializer.rb:11:in `represent'
  from app/serializers/environment_serializer.rb:27:in `block in represent'
  from app/serializers/environment_serializer.rb:24:in `map'
  from app/serializers/environment_serializer.rb:24:in `represent'
  from app/controllers/projects/environments_controller.rb:26:in `block (2 levels) in index'

ActionController::UrlGenerationError: No route matches {:action=>"folder", :controller=>"projects/environments", :id=>"", :namespace_id=>#<Group id:785414 @issue-reproduce>, :project_id=>#<Project id:4588064 issue-reproduce/borken-environments-list>} missing required keys: [:id]

/cc @markglenfletcher

Steps to reproduce

  • Create a new project
  • Create a new environment with the following name:
  • /envo
  • Navigate back to environments list

Example Project

https://gitlab.com/issue-reproduce/borken-environments-list/environments

What is the current bug behavior?

500 error as above occurs

What is the expected correct behavior?

Environment list is displayed as normal

Relevant logs and/or screenshots

(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's very hard to read otherwise.)

Output of checks

reproduced on GitLab.com v10.1.1

Possible fixes

Edited by Mark Fletcher