Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Session replay not redacting buttons and other non UILabel texts #4277

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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
Loading