Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit Network text view to 2^16 characters to prevent it from crashing #6254

Merged
merged 7 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class HttpRequestView extends StatelessWidget {
Widget child;
child = isJson
? JsonViewer(encodedJson: data.requestBody!)
: Text(
data.requestBody!,
: TextViewer(
text: data.requestBody!,
style: theme.fixedFontStyle,
);
return Padding(
Expand Down Expand Up @@ -356,8 +356,8 @@ class HttpTextResponseViewer extends StatelessWidget {

return switch (currentLocalResponseType) {
NetworkResponseViewType.json => JsonViewer(encodedJson: responseBody),
NetworkResponseViewType.text => Text(
responseBody,
NetworkResponseViewType.text => TextViewer(
text: responseBody,
style: textStyle,
),
_ => const SizedBox(),
Expand Down
32 changes: 32 additions & 0 deletions packages/devtools_app/lib/src/shared/common_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,38 @@ class JsonViewer extends StatefulWidget {
State<JsonViewer> createState() => _JsonViewerState();
}

/// A wrapper for a Text widget, which allows for concatenating text if it
/// becomes too long.
class TextViewer extends StatelessWidget {
CoderDake marked this conversation as resolved.
Show resolved Hide resolved
const TextViewer({
super.key,
required this.text,
this.maxLength = 65536, //2^16
this.style,
});

final String text;
CoderDake marked this conversation as resolved.
Show resolved Hide resolved
// TODO: change the maxLength if we determine a more appropriate limit
// in https://github.com/flutter/devtools/issues/6263.
final int maxLength;
final TextStyle? style;

@override
Widget build(BuildContext context) {
final String displayText;
// Limit the length of the displayed text to maxLength
if (text.length > maxLength) {
displayText = '${text.substring(0, min(maxLength, text.length))}...';
} else {
displayText = text;
}
return Text(
displayText,
style: style,
);
}
}

class _JsonViewerState extends State<JsonViewer>
with ProvidedControllerMixin<DebuggerController, JsonViewer> {
late Future<void> _initializeTree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TODO: Remove this section if there are not any general updates.
TODO: Remove this section if there are not any general updates.

## Network profiler updates
TODO: Remove this section if there are not any general updates.
- Fixed a crash with large text in request or response - [#6254](https://github.com/flutter/devtools/pull/6254)

## Logging updates
TODO: Remove this section if there are not any general updates.
Expand Down
Loading