diff --git a/CHANGELOG.md b/CHANGELOG.md index e18ffbb7c67..e4b7fcab456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Add replay quality option for Objective-C (#4267) +### Fixes + +- Session replay not redacting buttons and other non UILabel texts (#4277) + ## 8.33.0 This release fixes a bug (#4230) that we introduced with a refactoring (#4101) released in [8.30.1](https://github.com/getsentry/sentry-cocoa/releases/tag/8.30.1). diff --git a/Sources/Swift/Tools/UIRedactBuilder.swift b/Sources/Swift/Tools/UIRedactBuilder.swift index a8efef15903..e74ff98e708 100644 --- a/Sources/Swift/Tools/UIRedactBuilder.swift +++ b/Sources/Swift/Tools/UIRedactBuilder.swift @@ -77,11 +77,18 @@ class UIRedactBuilder { } func containsIgnoreClass(_ ignoreClass: AnyClass) -> Bool { - return ignoreClassesIdentifiers.contains(ObjectIdentifier(ignoreClass)) + return ignoreClassesIdentifiers.contains(ObjectIdentifier(ignoreClass)) } func containsRedactClass(_ redactClass: AnyClass) -> Bool { - return redactClassesIdentifiers.contains(ObjectIdentifier(redactClass)) + var currentClass: AnyClass? = redactClass + while currentClass != nil && currentClass != UIView.self { + if let currentClass = currentClass, redactClassesIdentifiers.contains(ObjectIdentifier(currentClass)) { + return true + } + currentClass = currentClass?.superclass() + } + return false } func addIgnoreClass(_ ignoreClass: AnyClass) { diff --git a/Tests/SentryTests/UIRedactBuilderTests.swift b/Tests/SentryTests/UIRedactBuilderTests.swift index 725a8698797..ca3812a64d0 100644 --- a/Tests/SentryTests/UIRedactBuilderTests.swift +++ b/Tests/SentryTests/UIRedactBuilderTests.swift @@ -146,18 +146,15 @@ class UIRedactBuilderTests: XCTestCase { } func testIgnoreClasses() { - class AnotherLabel: UILabel { - } - let sut = UIRedactBuilder() - sut.addIgnoreClass(AnotherLabel.self) - rootView.addSubview(AnotherLabel(frame: CGRect(x: 20, y: 20, width: 40, height: 40))) + sut.addIgnoreClass(UILabel.self) + rootView.addSubview(UILabel(frame: CGRect(x: 20, y: 20, width: 40, height: 40))) let result = sut.redactRegionsFor(view: rootView, options: RedactOptions()) XCTAssertEqual(result.count, 0) } - func testRedactlasses() { + func testRedactClasses() { class AnotherView: UIView { } @@ -170,6 +167,18 @@ class UIRedactBuilderTests: XCTestCase { XCTAssertEqual(result.count, 1) } + func testRedactSubClass() { + class AnotherView: UILabel { + } + + let sut = UIRedactBuilder() + let view = AnotherView(frame: CGRect(x: 20, y: 20, width: 40, height: 40)) + rootView.addSubview(view) + + let result = sut.redactRegionsFor(view: rootView, options: RedactOptions()) + XCTAssertEqual(result.count, 1) + } + func testIgnoreView() { class AnotherLabel: UILabel { }