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

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

Issue 2619793002: Add offset to UTF8-decode format exceptions. (Closed)
Patch Set: Created 3 years, 11 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/utf8_test.dart » ('j') | no next file with comments »
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 0687bb145b18f9c2d44f43ef8383435b3e2fdada..6b9feceaa7b9e703ca77fc6cf3cee6a967597ee1 100644
--- a/sdk/lib/convert/utf.dart
+++ b/sdk/lib/convert/utf.dart
@@ -347,7 +347,7 @@ class Utf8Decoder extends Converter<List<int>, String>
StringBuffer buffer = new StringBuffer();
_Utf8Decoder decoder = new _Utf8Decoder(buffer, _allowMalformed);
decoder.convert(codeUnits, start, end);
- decoder.close();
+ decoder.flush(codeUnits, end);
return buffer.toString();
}
@@ -431,11 +431,15 @@ class _Utf8Decoder {
*
* This method throws if the input was partial and the decoder was
* constructed with `allowMalformed` set to `false`.
+ *
+ * The [source] and [offset] of the current position may be provided,
+ * and are included in the exception if one is thrown.
*/
- void flush() {
+ void flush([List<int> source, int offset]) {
if (hasPartialInput) {
if (!_allowMalformed) {
- throw new FormatException("Unfinished UTF-8 octet sequence");
+ throw new FormatException("Unfinished UTF-8 octet sequence",
+ source, offset);
}
_stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE);
_value = 0;
@@ -480,7 +484,8 @@ class _Utf8Decoder {
expectedUnits = 0;
if (!_allowMalformed) {
throw new FormatException(
- "Bad UTF-8 encoding 0x${unit.toRadixString(16)}");
+ "Bad UTF-8 encoding 0x${unit.toRadixString(16)}",
+ codeUnits, i);
}
_isFirstCharacter = false;
_stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE);
@@ -496,7 +501,8 @@ class _Utf8Decoder {
// encoding.
if (!_allowMalformed) {
throw new FormatException(
- "Overlong encoding of 0x${value.toRadixString(16)}");
+ "Overlong encoding of 0x${value.toRadixString(16)}",
+ codeUnits, i - extraUnits - 1);
}
expectedUnits = extraUnits = 0;
value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
@@ -504,7 +510,8 @@ class _Utf8Decoder {
if (value > _FOUR_BYTE_LIMIT) {
if (!_allowMalformed) {
throw new FormatException("Character outside valid Unicode range: "
- "0x${value.toRadixString(16)}");
+ "0x${value.toRadixString(16)}",
+ codeUnits, i - extraUnits - 1);
}
value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
}
@@ -532,7 +539,8 @@ class _Utf8Decoder {
// TODO(floitsch): should this be unit <= 0 ?
if (!_allowMalformed) {
throw new FormatException(
- "Negative UTF-8 code unit: -0x${(-unit).toRadixString(16)}");
+ "Negative UTF-8 code unit: -0x${(-unit).toRadixString(16)}",
+ codeUnits, i - 1);
}
_stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE);
} else {
@@ -555,7 +563,8 @@ class _Utf8Decoder {
}
if (!_allowMalformed) {
throw new FormatException(
- "Bad UTF-8 encoding 0x${unit.toRadixString(16)}");
+ "Bad UTF-8 encoding 0x${unit.toRadixString(16)}",
+ codeUnits, i - 1);
}
value = UNICODE_REPLACEMENT_CHARACTER_RUNE;
expectedUnits = extraUnits = 0;
« no previous file with comments | « no previous file | tests/lib/convert/utf8_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698