Skip to content

Commit

Permalink
Enable the silent flag for invalid string exceptions when building a …
Browse files Browse the repository at this point in the history
…TextSpan (flutter#138564)

This error can occur in a release app (for example, if the text comes from user input that is not valid UTF-16).  In that case, TextSpan will replace the invalid text with a placeholder character.
  • Loading branch information
jason-simmons committed Nov 16, 2023
1 parent 61d3710 commit d859865
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/flutter/lib/src/painting/text_span.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati
stack: stack,
library: 'painting library',
context: ErrorDescription('while building a TextSpan'),
silent: true,
));
// Use a Unicode replacement character as a substitute for invalid text.
builder.addText('\uFFFD');
Expand Down
7 changes: 4 additions & 3 deletions packages/flutter/test/painting/text_painter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,9 @@ void main() {
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/87543

test('TextPainter handles invalid UTF-16', () {
Object? exception;
FlutterErrorDetails? error;
FlutterError.onError = (FlutterErrorDetails details) {
exception = details.exception;
error = details;
};

final TextPainter painter = TextPainter()
Expand All @@ -1207,7 +1207,8 @@ void main() {
painter.layout();
// The layout should include one replacement character.
expect(painter.width, equals(fontSize));
expect(exception, isNotNull);
expect(error!.exception, isNotNull);
expect(error!.silent, isTrue);
painter.dispose();
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87544

Expand Down

0 comments on commit d859865

Please sign in to comment.