Visitar URL original
Dump the source bytes if incorrect UTF-8 sequences are present by blasten · Pull Request #19 · flutter/packages · GitHub
Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clean up
  • Loading branch information
blasten committed May 1, 2019
commit 24bc6a1a4bf30cca28ab091405956a5e7b001d05
4 changes: 1 addition & 3 deletions packages/multicast_dns/lib/src/packet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,15 @@ _FQDNReadResult _readFQDN(
Uint8List.view(data.buffer, offset, partLength);
offset += partLength;

String partString;
try {
partString = utf8.decode(partBytes);
parts.add(utf8.decode(partBytes));
} on FormatException {
throw MDnsDecodeException(offset,
detailError: 'Bad UTF-8 encoding found while decoding string. '

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just message instead of detailError

'The Flutter team would greatly appreciate if you could file a bug or leave a'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is too specific for a general purpose package. the flutter_tool should add the flutter specific phrasing if it catches this error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we should probably either create a new type of exception or add an error code field to this one. I would probably lean towards a new type of exception that derives from MDnsDecodeException, e.g. MDnsUtf8DecodeException that still has the offset as well as the byte list. That way the tool could do a catch on it and do whatever it thinks is necessary with the byte array.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, I also lean toward a new type of exception.

'comment on the issue https://github.com/flutter/flutter/issues/31854.\n'
'The source bytes were:\n$partBytes\n\n');
}
parts.add(partString);
} else {
break;
}
Expand Down