From d73e64a24d4957ca7ed0b0f831df887431413ca5 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Mon, 30 Oct 2023 17:30:19 +0100 Subject: [PATCH] Quote additional arguments passed to xcodebuild/swift --- CHANGELOG.md | 1 + Sources/XcodeSupport/Xcodebuild.swift | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de76c9932..10bc7b6a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Fix redundant public accessibility analysis for protocol members declared in extensions that are referenced cross-module where the protocol itself is not. - Remove checks causing errors when scanning multi-platform projects. +- Additional arguments passed through to xcodebuild/swift are now quoted automatically as needed. ## 2.16.0 (2023-09-27) diff --git a/Sources/XcodeSupport/Xcodebuild.swift b/Sources/XcodeSupport/Xcodebuild.swift index b7e4a2f1e..e084c1617 100644 --- a/Sources/XcodeSupport/Xcodebuild.swift +++ b/Sources/XcodeSupport/Xcodebuild.swift @@ -40,7 +40,21 @@ public final class Xcodebuild { "INDEX_ENABLE_DATA_STORE=\"YES\"" ] - let xcodebuild = "xcodebuild \((args + [cmd] + envs + additionalArguments).joined(separator: " "))" + // Apply quotes to additional option values is needed. + var quotedArguments = additionalArguments + + for (i, arg) in additionalArguments.enumerated() { + if arg.hasPrefix("-"), + let value = additionalArguments[safe: i + 1], + !value.hasPrefix("-"), + !value.hasPrefix("\""), + !value.hasPrefix("\'") + { + quotedArguments[i + 1] = "\"\(value)\"" + } + } + + let xcodebuild = "xcodebuild \((args + [cmd] + envs + quotedArguments).joined(separator: " "))" return try shell.exec(["/bin/sh", "-c", xcodebuild]) }