From 02671d850aa5eb27ea7810311729a22911d2d3a1 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Tue, 13 Aug 2024 13:27:34 +0200 Subject: [PATCH] fix: Session replay not redacting buttons and other non UILabel texts (#4277) Subclasses of classes that should be redacted were not --- CHANGELOG.md | 4 ++++ Sources/Swift/Tools/UIRedactBuilder.swift | 11 ++++++++-- Tests/SentryTests/UIRedactBuilderTests.swift | 21 ++++++++++++++------ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fe6b8bff87..8b9252b1e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Pause replay in session mode when offline (#4264) - 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 { }