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

Side by Side Diff: sdk/lib/convert/html_escape.dart

Issue 1055283003: Fix off-by-one error in https://code.google.com/p/dart/source/detail?r=45153 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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
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 * A `String` converter that converts characters to HTML entities. 8 * A `String` converter that converts characters to HTML entities.
9 * 9 *
10 * This is intended to sanitice text before inserting the text into an HTML 10 * This is intended to sanitice text before inserting the text into an HTML
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 StringBuffer result = null; 175 StringBuffer result = null;
176 for (int i = start; i < end; i++) { 176 for (int i = start; i < end; i++) {
177 var ch = text[i]; 177 var ch = text[i];
178 String replacement = null; 178 String replacement = null;
179 switch (ch) { 179 switch (ch) {
180 case '&': replacement = '&amp;'; break; 180 case '&': replacement = '&amp;'; break;
181 case '"': if (mode.escapeQuot) replacement = '&quot;'; break; 181 case '"': if (mode.escapeQuot) replacement = '&quot;'; break;
182 case "'": if (mode.escapeApos) replacement = '&#39;'; break; 182 case "'": if (mode.escapeApos) replacement = '&#39;'; break;
183 case '<': if (mode.escapeLtGt) replacement = '&lt;'; break; 183 case '<': if (mode.escapeLtGt) replacement = '&lt;'; break;
184 case '>': if (mode.escapeLtGt) replacement = '&gt;'; break; 184 case '>': if (mode.escapeLtGt) replacement = '&gt;'; break;
185 case '/': if (mode.escapeSlash) replacement = '&#46;'; break; 185 case '/': if (mode.escapeSlash) replacement = '&#47;'; break;
186 } 186 }
187 if (replacement != null) { 187 if (replacement != null) {
188 if (result == null) result = new StringBuffer(); 188 if (result == null) result = new StringBuffer();
189 if (i > start) result.write(text.substring(start, i)); 189 if (i > start) result.write(text.substring(start, i));
190 result.write(replacement); 190 result.write(replacement);
191 start = i + 1; 191 start = i + 1;
192 } 192 }
193 } 193 }
194 if (result == null) return null; 194 if (result == null) return null;
195 if (end > start) result.write(text.substring(start, end)); 195 if (end > start) result.write(text.substring(start, end));
(...skipping 19 matching lines...) Expand all
215 if(val == null) { 215 if(val == null) {
216 _sink.addSlice(chunk, start, end, isLast); 216 _sink.addSlice(chunk, start, end, isLast);
217 } else { 217 } else {
218 _sink.add(val); 218 _sink.add(val);
219 if (isLast) _sink.close(); 219 if (isLast) _sink.close();
220 } 220 }
221 } 221 }
222 222
223 void close() => _sink.close(); 223 void close() => _sink.close();
224 } 224 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/serve/404_page_test.dart ('k') | tests/lib/convert/html_escape_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698