Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: sdk/lib/convert/utf.dart

Issue 22929022: Treat negative utf8-units the same way as other broken encodings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/convert/utf82_test.dart » ('j') | tests/lib/convert/utf82_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/convert/utf.dart
diff --git a/sdk/lib/convert/utf.dart b/sdk/lib/convert/utf.dart
index 80f7a7837f15ece8586f67385f46b0d3b5f3fd03..5a6cfe6ade59c9c2ffc7248eec783c9694f04492 100644
--- a/sdk/lib/convert/utf.dart
+++ b/sdk/lib/convert/utf.dart
@@ -455,7 +455,14 @@ class _Utf8Decoder {
while (i < endIndex) {
int unit = codeUnits[i++];
- if (unit <= _ONE_BYTE_LIMIT) {
+ if (unit < 0) {
Lasse Reichstein Nielsen 2013/08/22 06:10:42 Would it be cheaper/faster to do: if ((unit & ~0
floitsch 2013/08/22 15:40:25 Rapidly tried it, but somehow introduced a bug. No
+ // TODO(floitsch): should this be unit <= 0 ?
Lasse Reichstein Nielsen 2013/08/22 06:10:42 No, zero is a valid UTF-8 code unit encoding the U
floitsch 2013/08/22 15:40:25 Done.
+ if (!_allowMalformed) {
+ throw new FormatException(
+ "Negative UTF-8 code unit: -0x${(-unit).toRadixString(16)}");
+ }
+ _stringSink.writeCharCode(_REPLACEMENT_CHARACTER);
+ } else if (unit <= _ONE_BYTE_LIMIT) {
_isFirstCharacter = false;
_stringSink.writeCharCode(unit);
} else {
« no previous file with comments | « no previous file | tests/lib/convert/utf82_test.dart » ('j') | tests/lib/convert/utf82_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698