Skip to content

Commit f934650

Browse files
denraseGiancarlo Buenaflorbuenaflor
authored
Replay: Mask RichText Widgets (#2975)
* Mask RichText * add cl entry * format * Fix test * Fix test --------- Co-authored-by: Giancarlo Buenaflor <[email protected]> Co-authored-by: Giancarlo Buenaflor <[email protected]> Co-authored-by: Giancarlo Buenaflor <[email protected]>
1 parent cd41125 commit f934650

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Enhancements
6+
7+
- Replay: Mask RichText Widgets ([#2975](https://github.com/getsentry/sentry-dart/pull/2975))
8+
39
## 9.0.0-RC.3
410

511
### Features

flutter/example/lib/main.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ class MainScaffold extends StatelessWidget {
201201
body: SingleChildScrollView(
202202
child: Column(
203203
children: [
204+
RichText(
205+
text: const TextSpan(
206+
text: '(I am) Rich Text',
207+
style: TextStyle(
208+
color: Colors.black,
209+
fontSize: 16,
210+
),
211+
),
212+
),
204213
if (_isIntegrationTest) const IntegrationTestWidget(),
205214
const Center(child: Text('Trigger an action.\n')),
206215
const Padding(

flutter/lib/src/sentry_privacy_options.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class SentryPrivacyOptions {
6969
mask: true,
7070
name: 'EditableText',
7171
));
72+
rules.add(const SentryMaskingConstantRule<RichText>(
73+
mask: true,
74+
name: 'RichText',
75+
));
7276
}
7377

7478
// In Debug mode, check if users explicitly mask (or unmask) widgets that

flutter/test/screenshot/masking_config_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ void main() async {
168168
'SentryMaskingCustomRule<Image>(Mask all images except asset images.)',
169169
'SentryMaskingConstantRule<Text>(mask)',
170170
'SentryMaskingConstantRule<EditableText>(mask)',
171+
'SentryMaskingConstantRule<RichText>(mask)',
171172
'SentryMaskingCustomRule<Widget>(Debug-mode-only warning for potentially sensitive widgets.)'
172173
]);
173174
});
@@ -205,6 +206,7 @@ void main() async {
205206
...alwaysEnabledRules,
206207
'SentryMaskingConstantRule<Text>(mask)',
207208
'SentryMaskingConstantRule<EditableText>(mask)',
209+
'SentryMaskingConstantRule<RichText>(mask)',
208210
'SentryMaskingCustomRule<Widget>(Debug-mode-only warning for potentially sensitive widgets.)'
209211
]);
210212
});
@@ -226,6 +228,7 @@ void main() async {
226228
'SentryMaskingCustomRule<Image>(Mask all images except asset images.)',
227229
'SentryMaskingConstantRule<Text>(mask)',
228230
'SentryMaskingConstantRule<EditableText>(mask)',
231+
'SentryMaskingConstantRule<RichText>(mask)',
229232
'SentryMaskingCustomRule<Widget>(Debug-mode-only warning for potentially sensitive widgets.)'
230233
];
231234
test('mask() takes precedence', () {

flutter/test/screenshot/test_widget.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,27 @@ Future<Element> pumpTestElement(WidgetTester tester,
2121
padding: EdgeInsets.all(15),
2222
child: Center(child: Text('Centered text')),
2323
),
24+
newRichText(),
2425
ElevatedButton(
2526
onPressed: () {},
2627
child: Text('Button title'),
2728
),
2829
newCustomImage(),
2930
// Invisible widgets won't be obscured.
3031
Visibility(visible: false, child: Text('Invisible text')),
32+
Visibility(
33+
visible: false,
34+
child: newRichText(text: 'Invisible Rich Text')),
3135
Visibility(visible: false, child: newImage()),
3236
Opacity(opacity: 0, child: Text('Invisible text')),
37+
Opacity(
38+
opacity: 0,
39+
child: newRichText(text: 'Invisible Rich Text')),
3340
Opacity(opacity: 0, child: newImage()),
3441
Offstage(offstage: true, child: Text('Offstage text')),
42+
Offstage(
43+
offstage: true,
44+
child: newRichText(text: 'Offstage Rich Text')),
3545
Offstage(offstage: true, child: newImage()),
3646
Text(dummyText),
3747
Material(child: TextFormField()),
@@ -92,3 +102,10 @@ class CustomImageWidget extends Image {
92102
CustomImageWidget.memory(super.bytes, {super.key, super.width, super.height})
93103
: super.memory();
94104
}
105+
106+
RichText newRichText({String text = 'Rich Text'}) => RichText(
107+
text: TextSpan(
108+
text: text,
109+
style: const TextStyle(color: Colors.black, fontSize: 16),
110+
),
111+
);

flutter/test/screenshot/widget_filter_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void main() async {
4545
context: element,
4646
root: element.renderObject as RenderRepaintBoundary,
4747
colorScheme: colorScheme);
48-
expect(sut.items.length, 6);
48+
expect(sut.items.length, 7);
4949
});
5050

5151
testWidgets('does not redact text when disabled', (tester) async {
@@ -77,7 +77,7 @@ void main() async {
7777
context: element,
7878
root: element.renderObject as RenderRepaintBoundary,
7979
colorScheme: colorScheme);
80-
expect(sut.items.length, 6);
80+
expect(sut.items.length, 7);
8181
expect(
8282
sut.items.map(boundsRect),
8383
unorderedEquals([
@@ -87,6 +87,7 @@ void main() async {
8787
'800x24',
8888
'800x24',
8989
'50x20',
90+
'144x16',
9091
]));
9192
});
9293
});

0 commit comments

Comments
 (0)