Skip to content

Commit e188665

Browse files
committed
Ensure command is safe
1 parent a40a731 commit e188665

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
.library(name: "ShellOut", targets: ["ShellOut"])
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/SwiftPackageIndex/ShellQuote", from: "1.0.0"),
17+
.package(url: "https://github.com/SwiftPackageIndex/ShellQuote", from: "1.0.1"),
1818
],
1919
targets: [
2020
.target(

Sources/ShellOut.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ import ShellQuote
3939
environment: [String : String]? = nil,
4040
quoteArguments: Bool = true
4141
) throws -> String {
42+
guard !ShellQuote.hasUnsafeContent(command) else {
43+
throw ShellOutCommand.Error(message: "Command must not contain characters that require quoting.")
44+
}
4245
let arguments = quoteArguments ? arguments.map(ShellQuote.quote) : arguments
43-
print("*** arguments: ", arguments)
4446
let command = "cd \(path.escapingSpaces) && \(command) \(arguments.joined(separator: " "))"
4547

4648
return try process.launchBash(
@@ -407,6 +409,13 @@ extension ShellOutError: LocalizedError {
407409
}
408410
}
409411

412+
extension ShellOutCommand {
413+
// TODO: consolidate with ShellOutError
414+
struct Error: Swift.Error {
415+
var message: String
416+
}
417+
}
418+
410419
// MARK: - Private
411420

412421
private extension Process {

0 commit comments

Comments
 (0)