diff --git a/src/Common/AzureDevOps/AzureDevOpsUrlParser.cs b/src/Common/AzureDevOps/AzureDevOpsUrlParser.cs index e90eb3cd..dc8635a7 100644 --- a/src/Common/AzureDevOps/AzureDevOpsUrlParser.cs +++ b/src/Common/AzureDevOps/AzureDevOpsUrlParser.cs @@ -67,7 +67,7 @@ public static bool TryParseHostedHttp(string host, string relativeUrl, [NotNullW } projectPath = projectName ?? repositoryName; - + if (!isVisualStudioHost) { if (teamName != null) @@ -106,7 +106,7 @@ public static bool TryParseOnPremHttp(string relativeUrl, string virtualDirector return false; } - projectPath = string.Join("/", parts, 0, virtualDirectoryParts.Length) + "/" + collection + "/" + (projectName ?? repositoryName); + projectPath = string.Join("/", parts, 0, virtualDirectoryParts.Length) + "/" + collection + "/" + Uri.EscapeDataString(projectName ?? repositoryName); return true; } @@ -176,7 +176,7 @@ public static bool TryParseOnPremSsh(Uri uri, [NotNullWhen(true)]out string? rep repositoryPath = string.Join("/", parts, 0, teamNameIndex + 1); return true; } - + private static bool TryParsePath(string[] parts, int startIndex, string? type, [NotNullWhen(true)]out string? repositoryPath, [NotNullWhen(true)]out string? repositoryName) { if (TryParsePath(parts, startIndex, type, out var projectName, out var teamName, out repositoryName)) diff --git a/src/SourceLink.AzureDevOpsServer.Git.UnitTests/AzureDevOpsUrlParserOnPremTests.cs b/src/SourceLink.AzureDevOpsServer.Git.UnitTests/AzureDevOpsUrlParserOnPremTests.cs index 95e5bc49..0e2759fe 100644 --- a/src/SourceLink.AzureDevOpsServer.Git.UnitTests/AzureDevOpsUrlParserOnPremTests.cs +++ b/src/SourceLink.AzureDevOpsServer.Git.UnitTests/AzureDevOpsUrlParserOnPremTests.cs @@ -36,6 +36,7 @@ public void TryParseOnPremHttp_Error(string relativeUrl, string virtualDir = "/" [Theory] [InlineData("/collection/project/team/_git/repo", "/", "/collection/project", "repo")] [InlineData("/collection/project/_git/repo", "/", "/collection/project", "repo")] + [InlineData("/collection/project name/_git/repo", "/", "/collection/project%20name", "repo")] [InlineData("/collection/_git/repo/", "/", "/collection/repo", "repo")] [InlineData("/collection/_git/repo", "/", "/collection/repo", "repo")] [InlineData("/virtual/iis/path/collection/project/team/_git/repo", "/virtual/iis/path", "virtual/iis/path/collection/project", "repo")]