Skip to content

Commit cb336e7

Browse files
Guard KVC access for accessibilityCustomContent with responds(to:) (#314)
Prevent potential NSUnknownKeyException crash when value(forKey:) is called on NSObject subclasses that don't have the accessibilityCustomContent key and override valueForUndefinedKey: to throw. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fa60134 commit cb336e7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Sources/AccessibilitySnapshot/Parser/Swift/Classes/AccessibilityHierarchyParser.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ private extension NSObject {
852852

853853
// SwiftUI creates internal accessibility proxy nodes that don't explicitly conform to AXCustomContentProvider
854854
// but do expose accessibilityCustomContent via KVC
855-
if let content = value(forKey: "accessibilityCustomContent") as? [AXCustomContent] {
855+
if responds(to: Selector(("accessibilityCustomContent"))),
856+
let content = value(forKey: "accessibilityCustomContent") as? [AXCustomContent]
857+
{
856858
return content.map { .init(from: $0) }
857859
}
858860
}

0 commit comments

Comments
 (0)