Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

A variable typed in quotes reaches Wine without them. No shell reads the environment editor's values, so quotes around one went to the program as part of it, and macOS's text view turns typed quotes curly: a player's WINEDEBUG arrived as " loaddll” and Wine read no channel from it (highball-db#862). A value wrapped in one pair of quotes, straight or curly, now loses that pair; quotes inside a value stay (DXVK_CONFIG's customDeviceDesc="…"). (#654)

Gauthier Piarretted5af52ff4abf
diff --git a/Sources/HighballKit/EnvText.swift b/Sources/HighballKit/EnvText.swift
index 15b2037..e37f7e5 100644
--- a/Sources/HighballKit/EnvText.swift
+++ b/Sources/HighballKit/EnvText.swift
@@ -19,7 +19,7 @@ public enum EnvText {
let parts = line.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false).map(String.init)
let key = parts.first?.trimmingCharacters(in: .whitespaces) ?? ""
if parts.count == 2, !key.isEmpty, key.range(of: "^[A-Za-z_][A-Za-z0-9_]*$", options: .regularExpression) != nil {
- env[key] = parts[1]
+ env[key] = unquoted(parts[1])
} else {
ignored.append(line)
}
@@ -27,6 +27,18 @@ public enum EnvText {
return Parsed(environment: env, ignored: ignored)
}
+ /// No shell reads these values, so quotes typed around one reached the program as part of it.
+ /// A value wrapped in one pair of quotes, straight or the curly ones macOS's text view types
+ /// for them, is taken without that pair: a player's WINEDEBUG arrived as `" loaddll”` and Wine
+ /// read no channel from it (highball-db#862). Quotes inside a value stay, as in DXVK_CONFIG's
+ /// customDeviceDesc="…".
+ static func unquoted(_ value: String) -> String {
+ let quotes: Set<Character> = ["\"", "'", "\u{201C}", "\u{201D}", "\u{201E}", "\u{2018}", "\u{2019}"]
+ guard value.count >= 2, let first = value.first, let last = value.last,
+ quotes.contains(first), quotes.contains(last) else { return value }
+ return String(value.dropFirst().dropLast()).trimmingCharacters(in: .whitespaces)
+ }
+
public static func text(for environment: [String: String]) -> String {
environment.sorted { $0.key < $1.key }.map { "\($0.key)=\($0.value)" }.joined(separator: "\n")
}
diff --git a/Tests/HighballKitTests/EnvTextTests.swift b/Tests/HighballKitTests/EnvTextTests.swift
index fea9fa9..a7a10c6 100644
--- a/Tests/HighballKitTests/EnvTextTests.swift
+++ b/Tests/HighballKitTests/EnvTextTests.swift
@@ -13,6 +13,17 @@ final class EnvTextTests: XCTestCase {
XCTAssertEqual(EnvText.parse("DXMT_METAL_HUD=").environment, ["DXMT_METAL_HUD": ""])
}
+ /// highball-db#862: macOS turned the typed quotes curly, and the value reached Wine with them.
+ func testAValueInOnePairOfQuotesLosesThem() {
+ let p = EnvText.parse("WINEDEBUG=\" loaddll\u{201D}\nA='x y'\nB=\u{201C}+seh\u{201D}\nC=dxgi.customDeviceDesc=\"Intel(R) Arc\"\nD=\"\nE=plain")
+ XCTAssertEqual(p.environment["WINEDEBUG"], "loaddll")
+ XCTAssertEqual(p.environment["A"], "x y")
+ XCTAssertEqual(p.environment["B"], "+seh")
+ XCTAssertEqual(p.environment["C"], "dxgi.customDeviceDesc=\"Intel(R) Arc\"", "quotes inside a value stay")
+ XCTAssertEqual(p.environment["D"], "\"", "a lone quote is not a pair")
+ XCTAssertEqual(p.environment["E"], "plain")
+ }
+
func testRoundTrip() {
let env = ["B": "2", "A": "1"]
XCTAssertEqual(EnvText.text(for: env), "A=1\nB=2")