Skip to content

Commit 5d8e6fb

Browse files
committed
Fix package resolutions with spaces in names
1 parent c8515e5 commit 5d8e6fb

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

source/Calamari.Common/Plumbing/Extensions/CrossPlatformExtensions.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@ public static string ExpandPathEnvironmentVariables(string path)
1414

1515
path = Regex.Replace(path, @"(?<!\\)\$([a-zA-Z0-9_]+)", "%$1%");
1616
path = Environment.ExpandEnvironmentVariables(path);
17-
18-
// Special case: If the path contains "%2F", which represents an encoded forward slash,
17+
// Special case: If the path contains URL-encoded forward slash (%2F) or space (%20),
1918
// we assume it's part of a URL-encoded filename and not an unexpanded environment variable.
2019
// In this case, we return the path as is to avoid incorrectly modifying the filename.
2120
// Example: "~/Octopus/Files/Data%2FFileTransferService%2FFileTransferService@S11.0.zip"
22-
// Here, %2F is part of the filename and should not be treated as an environment variable.
23-
if (path.Contains("%2F") || path.Contains("%2f"))
21+
// Example: "~/Octopus/Files/https_dev.azure.com_Org_ADO%20Repository@O1.0.0.zip"
22+
if (path.Contains("%2F") || path.Contains("%2f") || path.Contains("%20"))
2423
{
2524
return path;
2625
}
27-
2826
// Clean up any remaining unexpanded environment variables.
29-
// This removes any %VAR% patterns that weren't expanded,
3027
// ensuring only valid, expanded variables remain in the path.
3128
return Regex.Replace(path, @"(?<!\\)%([a-zA-Z0-9_]+)%", "");
3229
}

source/Calamari.Tests/Fixtures/Util/CrossPlatformFixture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public void TildePrefixReplacedWithHome()
4646
[TestCase("\\$MARIO_BROTHER/blah", "\\$MARIO_BROTHER/blah", Description = "Escaped dollar preserved")]
4747
[TestCase("$MARIO_BROTHER/blah%2fblah.zip", "LUIGI/blah%2fblah.zip", Description = "Linux-style variable ($VAR) is expanded, but URL-encoded slash (%2f) in filename is preserved")]
4848
[TestCase("%MARIO_BROTHER%/blah%2fblah.zip", "LUIGI/blah%2fblah.zip", Description = "Windows-style variable (%VAR%) is expanded, and URL-encoded slash (%2f) in filename is preserved")]
49+
[TestCase("$MARIO_BROTHER/blah%20blah.zip", "LUIGI/blah%20blah.zip", Description = "Linux-style variable ($VAR) is expanded, but URL-encoded space (%20) in filename is preserved")]
50+
[TestCase("%MARIO_BROTHER%/blah%20blah.zip", "LUIGI/blah%20blah.zip", Description = "Windows-style variable (%VAR%) is expanded, and URL-encoded space (%20) in filename is preserved")]
4951
[Category(TestCategory.CompatibleOS.OnlyNixOrMac)]
5052
public void NixEnvironmentVariableReplaced(string inputValue, string expectedResult)
5153
{

0 commit comments

Comments
 (0)