Skip to content

Commit 219fbcd

Browse files
committed
Shell escape arguments when printing jobs with -###
1 parent c607fea commit 219fbcd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Sources/SwiftDriverExecution/SwiftDriverExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public final class SwiftDriverExecutor: DriverExecutor {
8282

8383
public func description(of job: Job, forceResponseFiles: Bool) throws -> String {
8484
let (args, usedResponseFile) = try resolver.resolveArgumentList(for: job, forceResponseFiles: forceResponseFiles)
85-
var result = args.joined(separator: " ")
85+
var result = args.map { $0.spm_shellEscaped() }.joined(separator: " ")
8686

8787
if usedResponseFile {
8888
// Print the response file arguments as a comment.

Tests/SwiftDriverTests/JobExecutorTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ final class JobExecutorTests: XCTestCase {
289289
}
290290
}
291291

292+
func testShellEscapingArgsInJobDescription() throws {
293+
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(),
294+
processSet: ProcessSet(),
295+
fileSystem: localFileSystem,
296+
env: [:])
297+
let job = Job(moduleName: "Module",
298+
kind: .compile,
299+
tool: .absolute(.init("/path/to/the tool")),
300+
commandLine: [.path(.absolute(.init("/with space"))),
301+
.path(.absolute(.init("/withoutspace")))],
302+
inputs: [], primaryInputs: [], outputs: [])
303+
XCTAssertEqual(try executor.description(of: job, forceResponseFiles: false),
304+
"'/path/to/the tool' '/with space' /withoutspace")
305+
}
306+
292307
func testInputModifiedDuringMultiJobBuild() throws {
293308
try withTemporaryDirectory { path in
294309
let main = path.appending(component: "main.swift")

0 commit comments

Comments
 (0)