Skip to content

Commit

Permalink
fix: Masking text with transparent text color (#4499)
Browse files Browse the repository at this point in the history
* fix: Masking text with transparent text color

* Update CHANGELOG.md
  • Loading branch information
brustolin authored Nov 5, 2024
1 parent 16c38a2 commit 1223af7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- Add `maskedViewClasses` and `unmaskedViewClasses` to SentryReplayOptions init via dict (#4492)
- Add `quality` to SentryReplayOptions init via dict (#4495)

### Fixes

- Masking text with transparent text color (#4499)

## 8.39.0

### Removal of Experimental API
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swift/Tools/UIRedactBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class UIRedactBuilder {
}

private func color(for view: UIView) -> UIColor? {
return (view as? UILabel)?.textColor
return (view as? UILabel)?.textColor.withAlphaComponent(1)
}

/**
Expand Down
10 changes: 10 additions & 0 deletions Tests/SentryTests/UIRedactBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class UIRedactBuilderTests: XCTestCase {
XCTAssertEqual(result.first?.transform, CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: 20, ty: 20))
}

func testDontUseLabelTransparentColor() {
let sut = getSut()
let label = UILabel(frame: CGRect(x: 20, y: 20, width: 40, height: 40))
label.textColor = .purple.withAlphaComponent(0.5)
rootView.addSubview(label)

let result = sut.redactRegionsFor(view: rootView)
XCTAssertEqual(result.first?.color, .purple)
}

func testDontRedactALabelOptionDisabled() {
let sut = getSut(RedactOptions(maskAllText: false))
let label = UILabel(frame: CGRect(x: 20, y: 20, width: 40, height: 40))
Expand Down

0 comments on commit 1223af7

Please sign in to comment.