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

Side by Side 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: Address comments. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/convert/utf82_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * An instance of the default implementation of the [Utf8Codec]. 8 * An instance of the default implementation of the [Utf8Codec].
9 * 9 *
10 * This instance provides a convenient access to the most common UTF-8 10 * This instance provides a convenient access to the most common UTF-8
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 value = _REPLACEMENT_CHARACTER; 448 value = _REPLACEMENT_CHARACTER;
449 } 449 }
450 if (!_isFirstCharacter || value != _BOM_CHARACTER) { 450 if (!_isFirstCharacter || value != _BOM_CHARACTER) {
451 _stringSink.writeCharCode(value); 451 _stringSink.writeCharCode(value);
452 } 452 }
453 _isFirstCharacter = false; 453 _isFirstCharacter = false;
454 } 454 }
455 455
456 while (i < endIndex) { 456 while (i < endIndex) {
457 int unit = codeUnits[i++]; 457 int unit = codeUnits[i++];
458 if (unit <= _ONE_BYTE_LIMIT) { 458 // TODO(floitsch): the way we test we could potentially allow
459 // units that are too large, if they happen to have the
460 // right bit-pattern. (Same is true for the multibyte loop above).
461 // TODO(floitsch): optimize this loop. See:
462 // https://codereview.chromium.org/22929022/diff/1/sdk/lib/convert/utf.d art?column_width=80
463 if (unit < 0) {
464 // TODO(floitsch): should this be unit <= 0 ?
465 if (!_allowMalformed) {
466 throw new FormatException(
467 "Negative UTF-8 code unit: -0x${(-unit).toRadixString(16)}");
468 }
469 _stringSink.writeCharCode(_REPLACEMENT_CHARACTER);
470 } else if (unit <= _ONE_BYTE_LIMIT) {
459 _isFirstCharacter = false; 471 _isFirstCharacter = false;
460 _stringSink.writeCharCode(unit); 472 _stringSink.writeCharCode(unit);
461 } else { 473 } else {
462 if ((unit & 0xE0) == 0xC0) { 474 if ((unit & 0xE0) == 0xC0) {
463 value = unit & 0x1F; 475 value = unit & 0x1F;
464 expectedUnits = extraUnits = 1; 476 expectedUnits = extraUnits = 1;
465 continue loop; 477 continue loop;
466 } 478 }
467 if ((unit & 0xF0) == 0xE0) { 479 if ((unit & 0xF0) == 0xE0) {
468 value = unit & 0x0F; 480 value = unit & 0x0F;
(...skipping 18 matching lines...) Expand all
487 } 499 }
488 break loop; 500 break loop;
489 } 501 }
490 if (expectedUnits > 0) { 502 if (expectedUnits > 0) {
491 _value = value; 503 _value = value;
492 _expectedUnits = expectedUnits; 504 _expectedUnits = expectedUnits;
493 _extraUnits = extraUnits; 505 _extraUnits = extraUnits;
494 } 506 }
495 } 507 }
496 } 508 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/convert/utf82_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698