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 commenthttps://gitlab.com/namespace/project.git # Change this laterhttps://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:
-
Preprocessing the URL: Using
url.split(' ').firstto extract only the URL part before any spaces, effectively removing comments and trailing content -
Preserving existing logic: The existing
.gitsuffix removal usingdelete_suffix!('.git')continues to work correctly after preprocessing
Edited by Vasilii Iakliushin