Skip to content

Commit

Permalink
fix: Session replay not redacting buttons and other non UILabel texts (
Browse files Browse the repository at this point in the history
…#4277)

Subclasses of classes that should be redacted were not
  • Loading branch information
brustolin authored Aug 13, 2024
1 parent 5c23b77 commit 02671d8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
11 changes: 9 additions & 2 deletions Sources/Swift/Tools/UIRedactBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 15 additions & 6 deletions Tests/SentryTests/UIRedactBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

Expand All @@ -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 {
}
Expand Down

0 comments on commit 02671d8

Please sign in to comment.