Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
3a51eb12
Unverified
Commit
3a51eb12
authored
Jun 24, 2021
by
Jason Simmons
Committed by
GitHub
Jun 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Substitute a replacement character for invalid UTF-16 text in a TextSpan (#84887)
parent
e1660e4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
text_span.dart
packages/flutter/lib/src/painting/text_span.dart
+14
-2
text_painter_test.dart
packages/flutter/test/painting/text_painter_test.dart
+19
-0
No files found.
packages/flutter/lib/src/painting/text_span.dart
View file @
3a51eb12
...
...
@@ -244,8 +244,20 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati
final
bool
hasStyle
=
style
!=
null
;
if
(
hasStyle
)
builder
.
pushStyle
(
style
!.
getTextStyle
(
textScaleFactor:
textScaleFactor
));
if
(
text
!=
null
)
builder
.
addText
(
text
!);
if
(
text
!=
null
)
{
try
{
builder
.
addText
(
text
!);
}
on
ArgumentError
catch
(
exception
,
stack
)
{
FlutterError
.
reportError
(
FlutterErrorDetails
(
exception:
exception
,
stack:
stack
,
library
:
'painting library'
,
context:
ErrorDescription
(
'while building a TextSpan'
),
));
// Use a Unicode replacement character as a substitute for invalid text.
builder
.
addText
(
'
\
uFFFD'
);
}
}
if
(
children
!=
null
)
{
for
(
final
InlineSpan
child
in
children
!)
{
assert
(
child
!=
null
);
...
...
packages/flutter/test/painting/text_painter_test.dart
View file @
3a51eb12
...
...
@@ -4,6 +4,7 @@
import
'dart:ui'
as
ui
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -952,6 +953,24 @@ void main() {
expect
(
glyphBox
,
newGlyphBox
);
});
},
skip:
isBrowser
);
test
(
'TextPainter handles invalid UTF-16'
,
()
{
Object
?
exception
;
FlutterError
.
onError
=
(
FlutterErrorDetails
details
)
{
exception
=
details
.
exception
;
};
final
TextPainter
painter
=
TextPainter
()
..
textDirection
=
TextDirection
.
ltr
;
const
String
text
=
'Hello
\
uD83DWorld'
;
const
double
fontSize
=
20.0
;
painter
.
text
=
const
TextSpan
(
text:
text
,
style:
TextStyle
(
fontSize:
fontSize
));
painter
.
layout
();
// The layout should include one replacement character.
expect
(
painter
.
width
,
equals
(
fontSize
));
expect
(
exception
,
isNotNull
);
},
skip:
kIsWeb
);
}
class
MockCanvas
extends
Fake
implements
Canvas
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment