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

Unified Diff: sdk/lib/io/string_stream.dart

Issue 11364115: Don't crash when decoding astral plane UTF-8. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years, 1 month 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/standalone/io/string_stream_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/string_stream.dart
diff --git a/sdk/lib/io/string_stream.dart b/sdk/lib/io/string_stream.dart
index 5d71af4245e6d1ff65f953000a9e87ffcad1c5d6..8f99c66272eb69f6394c0fc7d551a41656bfc2f4 100644
--- a/sdk/lib/io/string_stream.dart
+++ b/sdk/lib/io/string_stream.dart
@@ -85,22 +85,18 @@ abstract class _StringDecoderBase implements _StringDecoder {
int get lineBreaks => _lineBreaks;
- String decoded([int len]) {
+ String decoded([int length]) {
if (isEmpty) return null;
- String result;
- if (len !== null && len < available()) {
- result = new String.fromCharCodes(_result.getRange(_resultOffset, len));
+ List<int> result;
+ if (length != null && length < available()) {
+ result = _result.getRange(_resultOffset, length);
+ } else if (_resultOffset == 0) {
+ result = _result;
} else {
- if (_resultOffset == 0) {
- result = new String.fromCharCodes(_result);
- } else {
- result =
- new String.fromCharCodes(
- _result.getRange(_resultOffset,
- _result.length - _resultOffset));
- }
+ result = _result.getRange(_resultOffset, _result.length - _resultOffset);
}
+
_resultOffset += result.length;
while (!_lineBreakEnds.isEmpty &&
_lineBreakEnds.first < _charOffset + _resultOffset) {
@@ -108,7 +104,7 @@ abstract class _StringDecoderBase implements _StringDecoder {
_lineBreaks--;
}
if (_result.length == _resultOffset) _resetResult();
- return result;
+ return new String.fromCharCodes(result);
}
String get decodedLine {
@@ -419,7 +415,7 @@ class _StringInputStream implements StringInputStream {
void set onError(void callback(e)) {
_input.onError = callback;
- _decoder.onError = (e) {
+ _decoder.onError = (e) {
_clientCloseHandler = null;
_input.close();
callback(e);
« no previous file with comments | « no previous file | tests/standalone/io/string_stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698