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

Unified Diff: tool/input_sdk/lib/convert/latin1.dart

Issue 1965563003: Update dart:convert and dart:core Uri. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
Index: tool/input_sdk/lib/convert/latin1.dart
diff --git a/tool/input_sdk/lib/convert/latin1.dart b/tool/input_sdk/lib/convert/latin1.dart
index 7f7fef883ca18a23d209a27193fdfea92e7ff277..1d8546d189b4b052a48c77586a97f2d3f047ad4e 100644
--- a/tool/input_sdk/lib/convert/latin1.dart
+++ b/tool/input_sdk/lib/convert/latin1.dart
@@ -59,9 +59,9 @@ class Latin1Codec extends Encoding {
}
}
- Converter<String, List<int>> get encoder => const Latin1Encoder();
+ Latin1Encoder get encoder => const Latin1Encoder();
- Converter<List<int>, String> get decoder =>
+ Latin1Decoder get decoder =>
_allowInvalid ? const Latin1Decoder(allowInvalid: true)
: const Latin1Decoder(allowInvalid: false);
}
@@ -116,6 +116,7 @@ class _Latin1DecoderSink extends ByteConversionSinkBase {
void close() {
_sink.close();
+ _sink = null;
}
void add(List<int> source) {
@@ -132,19 +133,40 @@ class _Latin1DecoderSink extends ByteConversionSinkBase {
}
void addSlice(List<int> source, int start, int end, bool isLast) {
- RangeError.checkValidRange(start, end, source.length);
+ end = RangeError.checkValidRange(start, end, source.length);
+ if (start == end) return;
+ if (source is! Uint8List) {
+ // List may contain value outside of the 0..255 range. If so, throw.
+ // Technically, we could excuse Uint8ClampedList as well, but it unlikely
+ // to be relevant.
+ _checkValidLatin1(source, start, end);
+ }
+ _addSliceToSink(source, start, end, isLast);
+ }
+
+ static void _checkValidLatin1(List<int> source, int start, int end) {
+ int mask = 0;
for (int i = start; i < end; i++) {
- int char = source[i];
- if (char > _LATIN1_MASK || char < 0) {
- throw new FormatException("Source contains non-Latin-1 characters.");
- }
+ mask |= source[i];
}
- if (start < end) {
- _addSliceToSink(source, start, end, isLast);
+ if (mask >= 0 && mask <= _LATIN1_MASK) {
+ return;
}
- if (isLast) {
- close();
+ _reportInvalidLatin1(source, start, end); // Always throws.
+ }
+
+
+ static void _reportInvalidLatin1(List<int> source, int start, int end) {
+ // Find the index of the first non-Latin-1 character code.
+ for (int i = start; i < end; i++) {
+ int char = source[i];
+ if (char < 0 || char > _LATIN1_MASK) {
+ throw new FormatException("Source contains non-Latin-1 characters.",
+ source, i);
+ }
}
+ // Unreachable - we only call the function if the loop above throws.
+ assert(false);
}
}

Powered by Google App Engine
This is Rietveld 408576698