mirror of
https://github.com/actions/runner.git
synced 2025-12-12 15:13:30 +00:00
simplify logic to not use scripthandler
This commit is contained in:
@@ -20,31 +20,40 @@ namespace GitHub.Runner.Common.Tests.Worker.Handlers
|
|||||||
[Trait("Category", "Worker")]
|
[Trait("Category", "Worker")]
|
||||||
public void ScriptPath_WithSpaces_ShouldBeQuoted()
|
public void ScriptPath_WithSpaces_ShouldBeQuoted()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange - Test the path quoting logic that our fix addresses
|
||||||
using (TestHostContext hc = CreateTestContext())
|
var tempPathWithSpaces = "/path with spaces/_temp";
|
||||||
{
|
var scriptPathWithSpaces = Path.Combine(tempPathWithSpaces, "test-script.sh");
|
||||||
var scriptHandler = new ScriptHandler();
|
|
||||||
scriptHandler.Initialize(hc);
|
// Test the original (broken) behavior
|
||||||
|
var originalPath = scriptPathWithSpaces.Replace("\"", "\\\"");
|
||||||
// Create a mock temp directory path with spaces
|
|
||||||
var tempPathWithSpaces = "/path with spaces/_temp";
|
// Test our fix - properly quoted path
|
||||||
var scriptPathWithSpaces = Path.Combine(tempPathWithSpaces, "test-script.sh");
|
var quotedPath = $"\"{scriptPathWithSpaces.Replace("\"", "\\\"")}\"";
|
||||||
|
|
||||||
// Test the logic that our fix addresses
|
// Assert
|
||||||
var originalPath = scriptPathWithSpaces.Replace("\"", "\\\"");
|
Assert.False(originalPath.StartsWith("\""), "Original path should not be quoted");
|
||||||
var quotedPath = $"\"{scriptPathWithSpaces.Replace("\"", "\\\"")}\"";
|
Assert.True(quotedPath.StartsWith("\"") && quotedPath.EndsWith("\""), "Fixed path should be properly quoted");
|
||||||
|
Assert.Contains("path with spaces", quotedPath, StringComparison.Ordinal);
|
||||||
// Assert
|
|
||||||
Assert.False(originalPath.StartsWith("\""), "Original path should not be quoted");
|
// Verify the specific scenario that was failing
|
||||||
Assert.True(quotedPath.StartsWith("\"") && quotedPath.EndsWith("\""), "Fixed path should be properly quoted");
|
Assert.Equal("\"/path with spaces/_temp/test-script.sh\"", quotedPath);
|
||||||
Assert.Contains("path with spaces", quotedPath, StringComparison.Ordinal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestHostContext CreateTestContext([CallerMemberName] string testName = "")
|
[Fact]
|
||||||
|
[Trait("Level", "L0")]
|
||||||
|
[Trait("Category", "Worker")]
|
||||||
|
public void ScriptPath_WithQuotes_ShouldEscapeQuotes()
|
||||||
{
|
{
|
||||||
var hc = new TestHostContext(this, testName);
|
// Arrange - Test paths that contain quotes
|
||||||
return hc;
|
var pathWithQuotes = "/path/\"quoted folder\"/script.sh";
|
||||||
|
|
||||||
|
// Test our fix - properly escape quotes and wrap in quotes
|
||||||
|
var quotedPath = $"\"{pathWithQuotes.Replace("\"", "\\\"")}\"";
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal("\"/path/\\\"quoted folder\\\"/script.sh\"", quotedPath);
|
||||||
|
Assert.True(quotedPath.StartsWith("\"") && quotedPath.EndsWith("\""), "Path should be wrapped in quotes");
|
||||||
|
Assert.Contains("\\\"", quotedPath, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user