Fix submodule URL parsing to handle comments and trailing content

What does this MR do?

Fixes submodule URL parsing to properly handle comments and trailing content after .git in submodule URLs.

Sentry error: https://new-sentry.gitlab.net/organizations/gitlab/issues/1774576

ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"projects", :id=>"project.git # Gitlab PAT", :namespace_id=>"group/subgroup/subsubgroup"}, possible unmatched constraints: [:id] (ActionController::UrlGenerationError)
Did you mean?  namespace_project_url
  from action_dispatch/journey/formatter.rb:44:in `path'
  from action_dispatch/routing/route_set.rb:854:in `url_for'
  from action_dispatch/routing/route_set.rb:271:in `call'
  from action_dispatch/routing/route_set.rb:327:in `block in define_url_helper'
  from app/helpers/submodule_helper.rb:28:in `submodule_links_for_url'
  from lib/gitlab/submodule_links.rb:17:in `for'
  from lib/gitlab/graphql/representation/submodule_tree_entry.rb:15:in `block in decorate'
  from lib/gitlab/graphql/representation/submodule_tree_entry.rb:14:in `map'
  from lib/gitlab/graphql/representation/submodule_tree_entry.rb:14:in `decorate'

Problem

The current implementation only removes the .git suffix using delete_suffix!('.git') but doesn't handle cases where there are comments or additional text after .git.

For example, URLs like:

  • https://gitlab.com/namespace/project.git # This is a comment
  • https://gitlab.com/namespace/project.git # Change this later
  • https://gitlab.com/namespace/project.git some additional text

Would not be parsed correctly, leading to incorrect project names that include the comment text.

Solution

Updated the extract_namespace_project method to remove comments and trailing content by:

  1. Preprocessing the URL: Using url.split(' ').first to extract only the URL part before any spaces, effectively removing comments and trailing content
  2. Preserving existing logic: The existing .git suffix removal using delete_suffix!('.git') continues to work correctly after preprocessing
Edited by Vasilii Iakliushin

Merge request reports

Loading