Unverified Commit d859865e authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Enable the silent flag for invalid string exceptions when building a TextSpan (#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.
parent 61d37105
...@@ -285,6 +285,7 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati ...@@ -285,6 +285,7 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati
stack: stack, stack: stack,
library: 'painting library', library: 'painting library',
context: ErrorDescription('while building a TextSpan'), context: ErrorDescription('while building a TextSpan'),
silent: true,
)); ));
// Use a Unicode replacement character as a substitute for invalid text. // Use a Unicode replacement character as a substitute for invalid text.
builder.addText('\uFFFD'); builder.addText('\uFFFD');
......
...@@ -1193,9 +1193,9 @@ void main() { ...@@ -1193,9 +1193,9 @@ void main() {
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/87543 }, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/87543
test('TextPainter handles invalid UTF-16', () { test('TextPainter handles invalid UTF-16', () {
Object? exception; FlutterErrorDetails? error;
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.onError = (FlutterErrorDetails details) {
exception = details.exception; error = details;
}; };
final TextPainter painter = TextPainter() final TextPainter painter = TextPainter()
...@@ -1207,7 +1207,8 @@ void main() { ...@@ -1207,7 +1207,8 @@ void main() {
painter.layout(); painter.layout();
// The layout should include one replacement character. // The layout should include one replacement character.
expect(painter.width, equals(fontSize)); expect(painter.width, equals(fontSize));
expect(exception, isNotNull); expect(error!.exception, isNotNull);
expect(error!.silent, isTrue);
painter.dispose(); painter.dispose();
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87544 }, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87544
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment