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

Side by Side Diff: tools/dom/src/Validators.dart

Issue 1825373004: Check for the case where previousNode fails in sanitization. Can happen with object tags (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | 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) 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
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
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 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698