| OLD | NEW |
| 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 sanitize text before inserting the text into an HTML |
| 11 * document. Characters that are meaningful in HTML are converted to | 11 * document. Characters that are meaningful in HTML are converted to |
| 12 * HTML entities (like `&` for `&`). | 12 * HTML entities (like `&` for `&`). |
| 13 * | 13 * |
| 14 * The general converter escapes all characters that are meaningful in HTML | 14 * The general converter escapes all characters that are meaningful in HTML |
| 15 * attributes or normal element context. Elements with special content types | 15 * attributes or normal element context. Elements with special content types |
| 16 * (like CSS or JavaScript) may need a more specialized escaping that | 16 * (like CSS or JavaScript) may need a more specialized escaping that |
| 17 * understands that content type. | 17 * understands that content type. |
| 18 * | 18 * |
| 19 * If the context where the text will be inserted is known in more detail, | 19 * If the context where the text will be inserted is known in more detail, |
| 20 * it's possible to omit escaping some characters (like quotes when not | 20 * it's possible to omit escaping some characters (like quotes when not |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 this.escapeQuot: false, | 127 this.escapeQuot: false, |
| 128 this.escapeApos: false, | 128 this.escapeApos: false, |
| 129 this.escapeSlash: false}) : _name = name; | 129 this.escapeSlash: false}) : _name = name; |
| 130 | 130 |
| 131 String toString() => _name; | 131 String toString() => _name; |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * Converter which escapes characters with special meaning in HTML. | 135 * Converter which escapes characters with special meaning in HTML. |
| 136 * | 136 * |
| 137 * The converter finds characters that are siginificant in HTML source and | 137 * The converter finds characters that are significant in HTML source and |
| 138 * replaces them with corresponding HTML entities. | 138 * replaces them with corresponding HTML entities. |
| 139 * | 139 * |
| 140 * The characters that need escaping in HTML are: | 140 * The characters that need escaping in HTML are: |
| 141 * | 141 * |
| 142 * * `&` (ampersand) always need to be escaped. | 142 * * `&` (ampersand) always need to be escaped. |
| 143 * * `<` (less than) and '>' (greater than) when inside an element. | 143 * * `<` (less than) and '>' (greater than) when inside an element. |
| 144 * * `"` (quote) when inside a double-quoted attribute value. | 144 * * `"` (quote) when inside a double-quoted attribute value. |
| 145 * * `'` (apostrophe) when inside a single-quoted attribute value. | 145 * * `'` (apostrophe) when inside a single-quoted attribute value. |
| 146 * Apostrophe is escaped as `'` instead of `'` since | 146 * Apostrophe is escaped as `'` instead of `'` since |
| 147 * not all browsers understand `'`. | 147 * not all browsers understand `'`. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 if(val == null) { | 223 if(val == null) { |
| 224 _sink.addSlice(chunk, start, end, isLast); | 224 _sink.addSlice(chunk, start, end, isLast); |
| 225 } else { | 225 } else { |
| 226 _sink.add(val); | 226 _sink.add(val); |
| 227 if (isLast) _sink.close(); | 227 if (isLast) _sink.close(); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 void close() { _sink.close(); } | 231 void close() { _sink.close(); } |
| 232 } | 232 } |
| OLD | NEW |