@@ -785,9 +785,14 @@ function normalizeGooglesourceUrl(host: string, pathname: string): string | null
785785const OPENDALIGHT_GERRIT_HOST = 'git.opendaylight.org'
786786
787787function normalizeOpendaylightGerritUrl ( pathname : string , search : string ) : string | null {
788- const queryRepo = new URLSearchParams ( search ) . get ( 'p' )
788+ // Query extraction only applies to the actual gitweb browse script — a `p` query
789+ // on some unrelated path isn't a repo reference.
790+ const queryRepo = pathname === '/gerrit/gitweb' ? new URLSearchParams ( search ) . get ( 'p' ) : null
789791 const segments = pathname . split ( '/' ) . filter ( Boolean )
790- const rawName = queryRepo ?? ( segments . length === 1 ? segments [ 0 ] : null )
792+ // The one-segment SSH-clone form must end in .git, otherwise any arbitrary
793+ // single-segment path (e.g. /favicon.ico) would be mistaken for a repo.
794+ const rawName =
795+ queryRepo ?? ( segments . length === 1 && segments [ 0 ] . endsWith ( '.git' ) ? segments [ 0 ] : null )
791796 const name = rawName ? extractGitwebRepoName ( rawName ) : null
792797 if ( ! name ) return null
793798
@@ -876,9 +881,12 @@ export function isSvnHost(host: string): boolean {
876881 */
877882function normalizeSvnUrl ( host : string , pathname : string ) : string | null {
878883 const rest = pathname . replace ( / ^ \/ + / , '' )
879- const markerMatch = rest . match ( / ^ ( v i e w v c | v i e w c v s \. c g i | r e p o s \/ a s f | s v n r o o t | s v n | p ) \/ ( .* ) $ / )
884+ // The trailing group is optional so a marker-only root (e.g. "/repos/asf" with
885+ // no trailing slash) still matches, leaving an empty remainder instead of
886+ // falling through to be mis-parsed as project segments "repos"/"asf".
887+ const markerMatch = rest . match ( / ^ ( v i e w v c | v i e w c v s \. c g i | r e p o s \/ a s f | s v n r o o t | s v n | p ) (?: \/ ( .* ) ) ? $ / )
880888 const scriptPrefix = markerMatch ?. [ 1 ] ?? null
881- const afterPrefix = markerMatch ? markerMatch [ 2 ] : rest
889+ const afterPrefix = markerMatch ? ( markerMatch [ 2 ] ?? '' ) : rest
882890
883891 const segments = afterPrefix . split ( '/' ) . filter ( Boolean )
884892 if ( segments . some ( ( s ) => / \$ \{ | % 7 B / i. test ( s ) ) ) return null
0 commit comments