Files
ghostty/macos/Tests/Helpers/Extensions/StringExtensionTests.swift
Jon Parise 1ff0dd821f macos: quote input strings used for shell commands
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.
2026-02-05 09:21:37 -05:00

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)
}
}