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

Side by Side Diff: pkg/yaml/lib/src/scanner.dart

Issue 801573003: Fix a crashing yaml bug when parsing block scalars. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | « pkg/yaml/CHANGELOG.md ('k') | pkg/yaml/pubspec.yaml » ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library yaml.scanner; 5 library yaml.scanner;
6 6
7 import 'package:collection/collection.dart'; 7 import 'package:collection/collection.dart';
8 import 'package:string_scanner/string_scanner.dart'; 8 import 'package:string_scanner/string_scanner.dart';
9 import 'package:source_span/source_span.dart'; 9 import 'package:source_span/source_span.dart';
10 10
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 // needed. 1149 // needed.
1150 var pair = _scanBlockScalarBreaks(indent); 1150 var pair = _scanBlockScalarBreaks(indent);
1151 indent = pair.first; 1151 indent = pair.first;
1152 var trailingBreaks = pair.last; 1152 var trailingBreaks = pair.last;
1153 1153
1154 // Scan the block scalar contents. 1154 // Scan the block scalar contents.
1155 var buffer = new StringBuffer(); 1155 var buffer = new StringBuffer();
1156 var leadingBreak = ''; 1156 var leadingBreak = '';
1157 var leadingBlank = false; 1157 var leadingBlank = false;
1158 var trailingBlank = false; 1158 var trailingBlank = false;
1159 var end = _scanner.position; 1159 var end = _scanner.state;
1160 while (_scanner.column == indent && !_scanner.isDone) { 1160 while (_scanner.column == indent && !_scanner.isDone) {
1161 // Check for a document indicator. libyaml doesn't do this, but the spec 1161 // Check for a document indicator. libyaml doesn't do this, but the spec
1162 // mandates it. See example 9.5: 1162 // mandates it. See example 9.5:
1163 // http://yaml.org/spec/1.2/spec.html#id2801606. 1163 // http://yaml.org/spec/1.2/spec.html#id2801606.
1164 if (_isDocumentIndicator) break; 1164 if (_isDocumentIndicator) break;
1165 1165
1166 // We are at the beginning of a non-empty line. 1166 // We are at the beginning of a non-empty line.
1167 1167
1168 // Is there trailing whitespace? 1168 // Is there trailing whitespace?
1169 trailingBlank = _isBlank; 1169 trailingBlank = _isBlank;
(...skipping 12 matching lines...) Expand all
1182 buffer.write(trailingBreaks); 1182 buffer.write(trailingBreaks);
1183 1183
1184 // Is there leading whitespace? 1184 // Is there leading whitespace?
1185 leadingBlank = _isBlank; 1185 leadingBlank = _isBlank;
1186 1186
1187 var startPosition = _scanner.position; 1187 var startPosition = _scanner.position;
1188 while (!_isBreakOrEnd) { 1188 while (!_isBreakOrEnd) {
1189 _scanner.readChar(); 1189 _scanner.readChar();
1190 } 1190 }
1191 buffer.write(_scanner.substring(startPosition)); 1191 buffer.write(_scanner.substring(startPosition));
1192 end = _scanner.position; 1192 end = _scanner.state;
1193 1193
1194 // libyaml always reads a line here, but this breaks on block scalars at 1194 // libyaml always reads a line here, but this breaks on block scalars at
1195 // the end of the document that end without newlines. See example 8.1: 1195 // the end of the document that end without newlines. See example 8.1:
1196 // http://yaml.org/spec/1.2/spec.html#id2793888. 1196 // http://yaml.org/spec/1.2/spec.html#id2793888.
1197 if (!_scanner.isDone) leadingBreak = _readLine(); 1197 if (!_scanner.isDone) leadingBreak = _readLine();
1198 1198
1199 // Eat the following indentation and spaces. 1199 // Eat the following indentation and spaces.
1200 var pair = _scanBlockScalarBreaks(indent); 1200 var pair = _scanBlockScalarBreaks(indent);
1201 indent = pair.first; 1201 indent = pair.first;
1202 trailingBreaks = pair.last; 1202 trailingBreaks = pair.last;
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 1658
1659 /// All trailing whitespace is preserved. 1659 /// All trailing whitespace is preserved.
1660 static const KEEP = const _Chomping("KEEP"); 1660 static const KEEP = const _Chomping("KEEP");
1661 1661
1662 final String name; 1662 final String name;
1663 1663
1664 const _Chomping(this.name); 1664 const _Chomping(this.name);
1665 1665
1666 String toString() => name; 1666 String toString() => name;
1667 } 1667 }
OLDNEW
« no previous file with comments | « pkg/yaml/CHANGELOG.md ('k') | pkg/yaml/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698