Skip to content

Commit 9435060

Browse files
thymikeeclaude
andcommitted
fix(ios): take only the open and cancel labels of the SchemeApproval table
Another key of that undocumented table cannot join the accept or dismiss labels. The placeholder regex no longer force-unwraps. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent f862d9e commit 9435060

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAlertLabelVocabulary.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension RunnerAlertLabelVocabulary {
4848

4949
/// Every permission table must read, or none counts: a missing table could hide the translation
5050
/// that makes a label in another table claim both actions. The launch confirmation's table only
51-
/// adds its own open and cancel labels, so without it the permission vocabulary stays whole.
51+
/// adds its own open and cancel labels (only those two keys are taken), so without it the permission vocabulary stays whole.
5252
static func composed(
5353
permission: Result<[RunnerSystemPromptStrings], RunnerSystemPromptStrings.UnavailableSource>,
5454
launchConfirmation: Result<[RunnerSystemPromptStrings], RunnerSystemPromptStrings.UnavailableSource>,
@@ -66,7 +66,7 @@ extension RunnerAlertLabelVocabulary {
6666
case .failure(let failure):
6767
RunnerSystemPromptStrings.logUnavailable(failure, subsystem: "alert-vocabulary-launch-confirmation", languages: languages)
6868
case .success(let read):
69-
tables += read
69+
tables += read.map { $0.limited(to: RunnerSystemPromptStrings.launchConfirmationLabelKeys) }
7070
}
7171
var translations: [(english: String, localized: String)] = []
7272
for table in tables {

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerLaunchConfirmationPrompt.swift‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ struct RunnerLaunchConfirmationPrompt {
1313

1414
static let unavailable = RunnerLaunchConfirmationPrompt(wordings: [])
1515

16+
private static let appNamePlaceholder = try? NSRegularExpression(pattern: "%(?:\\d+\\$)?(?:\\[[^\\]]*\\])?@")
17+
1618
private let wordings: [(title: NSRegularExpression, open: String, cancel: String)]
1719

1820
/// A wording whose title format has no app-name placeholder is skipped, because its pattern would
1921
/// match a title with no app name. A placeholder is `%@`, a positional `%1$@`, or Apple's
2022
/// bracketed object format `%[tt]@`, as Finnish words it.
2123
init(wordings: [Wording]) {
22-
let placeholder = try! NSRegularExpression(pattern: "%(?:\\d+\\$)?(?:\\[[^\\]]*\\])?@")
24+
guard let placeholder = Self.appNamePlaceholder else {
25+
self.wordings = []
26+
return
27+
}
2328
self.wordings = wordings.compactMap { wording in
2429
let format = wording.titleFormat as NSString
2530
let slots = placeholder.matches(in: wording.titleFormat, range: NSRange(location: 0, length: format.length))

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSystemPromptStrings.swift‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ struct RunnerSystemPromptStrings {
1717

1818
/// SpringBoard's launch confirmation. It is read apart from `promptTables`, so a runtime without
1919
/// it keeps the permission prompts' vocabulary.
20+
/// The only keys of that table the alert vocabulary takes, so another key of an undocumented
21+
/// table cannot join the accept or dismiss labels.
22+
static let launchConfirmationLabelKeys: Set<String> = ["SCHEME_APPROVAL_OPEN_BUTTON", "SCHEME_APPROVAL_DO_NOT_OPEN_BUTTON"]
23+
2024
static let launchConfirmationTable = (
2125
path: "/System/Library/Frameworks/CoreServices.framework",
2226
table: "SchemeApproval"
@@ -52,6 +56,14 @@ struct RunnerSystemPromptStrings {
5256
return .success(read)
5357
}
5458

59+
/// This table restricted to `keys`.
60+
func limited(to keys: Set<String>) -> RunnerSystemPromptStrings {
61+
RunnerSystemPromptStrings(
62+
english: english.filter { keys.contains($0.key) },
63+
localized: localized.mapValues { $0.filter { keys.contains($0.key) } }
64+
)
65+
}
66+
5567
struct UnavailableSource: Error {
5668
let source: String
5769
}

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+LaunchConfirmationPromptTests.swift‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ extension RunnerTests {
134134
/// launch confirmation's own labels are lost.
135135
func testMissingSchemeApprovalTableKeepsThePermissionVocabulary() {
136136
let permission = RunnerSystemPromptStrings(english: ["DENY": "Don’t Allow"], localized: ["fr": ["DENY": "Refuser"]])
137-
let launch = RunnerSystemPromptStrings(english: ["OPEN": "Open"], localized: ["fr": ["OPEN": "Ouvrir"]])
137+
let launch = RunnerSystemPromptStrings(
138+
english: ["SCHEME_APPROVAL_OPEN_BUTTON": "Open", "SCHEME_APPROVAL_OTHER": "Continue"],
139+
localized: ["fr": ["SCHEME_APPROVAL_OPEN_BUTTON": "Ouvrir", "SCHEME_APPROVAL_OTHER": "Poursuivre"]]
140+
)
138141
let missing = RunnerSystemPromptStrings.UnavailableSource(source: "CoreServices.framework")
139142

140143
let without = RunnerAlertLabelVocabulary.composed(
@@ -147,6 +150,10 @@ extension RunnerTests {
147150
permission: .success([permission]), launchConfirmation: .success([launch]), languages: ["fr"]
148151
)
149152
XCTAssertEqual(RunnerAlertButtonChoice.buttonIndex(for: ["Annuler", "Ouvrir"], action: "accept", vocabulary: with), 1)
153+
XCTAssertNil(
154+
RunnerAlertButtonChoice.buttonIndex(for: ["Refuser", "Poursuivre"], action: "accept", vocabulary: with),
155+
"a key of the table other than its open and cancel labels adds no label"
156+
)
150157

151158
let noPermission = RunnerAlertLabelVocabulary.composed(
152159
permission: .failure(missing), launchConfirmation: .success([launch]), languages: ["fr"]

0 commit comments

Comments
 (0)