mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-18 05:20:29 +00:00
When we're building an input string that's explicitly meant to be used as a shell command, quote (escape) it using the same logic as Python's shlex.quote function. This specifically addresses issues we've seen when open(1)'ing Ghostty with filename arguments that contain spaces.
20 lines
566 B
Swift
20 lines
566 B
Swift
import Testing
|
|
@testable import Ghostty
|
|
|
|
struct StringExtensionTests {
|
|
@Test(arguments: [
|
|
("", "''"),
|
|
("filename", "filename"),
|
|
("abcABC123@%_-+=:,./", "abcABC123@%_-+=:,./"),
|
|
("file name", "'file name'"),
|
|
("file$name", "'file$name'"),
|
|
("file!name", "'file!name'"),
|
|
("file\\name", "'file\\name'"),
|
|
("it's", "'it'\"'\"'s'"),
|
|
("file$'name'", "'file$'\"'\"'name'\"'\"''"),
|
|
])
|
|
func shellQuoted(input: String, expected: String) {
|
|
#expect(input.shellQuoted() == expected)
|
|
}
|
|
}
|