Chromium Code Reviews| 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.dom.html; | 5 part of dart.dom.html; |
| 6 | 6 |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Interface used to validate that only accepted elements and attributes are | 9 * Interface used to validate that only accepted elements and attributes are |
| 10 * allowed while parsing HTML strings into DOM nodes. | 10 * allowed while parsing HTML strings into DOM nodes. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 */ | 160 */ |
| 161 class _ValidatingTreeSanitizer implements NodeTreeSanitizer { | 161 class _ValidatingTreeSanitizer implements NodeTreeSanitizer { |
| 162 NodeValidator validator; | 162 NodeValidator validator; |
| 163 _ValidatingTreeSanitizer(this.validator) {} | 163 _ValidatingTreeSanitizer(this.validator) {} |
| 164 | 164 |
| 165 void sanitizeTree(Node node) { | 165 void sanitizeTree(Node node) { |
| 166 void walk(Node node, Node parent) { | 166 void walk(Node node, Node parent) { |
| 167 sanitizeNode(node, parent); | 167 sanitizeNode(node, parent); |
| 168 | 168 |
| 169 var child = node.lastChild; | 169 var child = node.lastChild; |
| 170 while (child != null) { | 170 while (!identical(child, null)) { |
|
sra1
2016/03/25 17:20:12
!= null is fine - null as an explicit argument is
Alan Knight
2016/03/25 18:10:46
OK, just being extremely paranoid. Made it null !=
| |
| 171 // Child may be removed during the walk. | 171 var nextChild; |
| 172 var nextChild = child.previousNode; | 172 try { |
| 173 // Child may be removed during the walk, and we may not | |
| 174 // even be able to get its previousNode. | |
| 175 nextChild = child.previousNode; | |
| 176 } catch (e) { | |
| 177 // child appears bad, remove it and restart the traversal without it. | |
|
sra1
2016/03/25 17:20:12
Say why a restart is necessary instead of just rem
Alan Knight
2016/03/25 18:10:46
Added comment. Rewrote it to not be recursive.
| |
| 178 _removeNode(child, node); | |
| 179 walk(node, parent); | |
| 180 return; | |
| 181 } | |
| 173 walk(child, node); | 182 walk(child, node); |
| 174 child = nextChild; | 183 child = nextChild; |
| 175 } | 184 } |
| 176 } | 185 } |
| 177 walk(node, null); | 186 walk(node, null); |
| 178 } | 187 } |
| 179 | 188 |
| 180 /// Aggressively try to remove node. | 189 /// Aggressively try to remove node. |
| 181 void _removeNode(Node node, Node parent) { | 190 void _removeNode(Node node, Node parent) { |
| 182 // If we have the parent, it's presumably already passed more sanitization | 191 // If we have the parent, it's presumably already passed more sanitization |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 case Node.COMMENT_NODE: | 296 case Node.COMMENT_NODE: |
| 288 case Node.DOCUMENT_FRAGMENT_NODE: | 297 case Node.DOCUMENT_FRAGMENT_NODE: |
| 289 case Node.TEXT_NODE: | 298 case Node.TEXT_NODE: |
| 290 case Node.CDATA_SECTION_NODE: | 299 case Node.CDATA_SECTION_NODE: |
| 291 break; | 300 break; |
| 292 default: | 301 default: |
| 293 _removeNode(node, parent); | 302 _removeNode(node, parent); |
| 294 } | 303 } |
| 295 } | 304 } |
| 296 } | 305 } |
| OLD | NEW |