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 | 161 |
162 /// Aggressively try to remove node. | 162 /// Aggressively try to remove node. |
163 void _removeNode(Node node, Node parent) { | 163 void _removeNode(Node node, Node parent) { |
164 // If we have the parent, it's presumably already passed more sanitization o
r | 164 // If we have the parent, it's presumably already passed more sanitization o
r |
165 // is the fragment, so ask it to remove the child. And if that fails try to | 165 // is the fragment, so ask it to remove the child. And if that fails try to |
166 // set the outer html. | 166 // set the outer html. |
167 if (parent == null) { | 167 if (parent == null) { |
168 node.remove(); | 168 node.remove(); |
169 } else { | 169 } else { |
170 try { | 170 parent._removeChild(node); |
171 parent._removeChild(node); | |
172 } catch (e) { | |
173 node.outerHtml = ''; | |
174 } | |
175 } | 171 } |
176 } | 172 } |
177 | 173 |
178 void sanitizeNode(Node node, Node parent) { | 174 void sanitizeNode(Node node, Node parent) { |
179 switch (node.nodeType) { | 175 switch (node.nodeType) { |
180 case Node.ELEMENT_NODE: | 176 case Node.ELEMENT_NODE: |
181 Element element = node; | 177 Element element = node; |
182 if (element._hasCorruptedAttributes) { | 178 if (element._hasCorruptedAttributes) { |
183 window.console.warn('Removing element due to corrupted attributes on <
${element}>'); | 179 window.console.warn('Removing element due to corrupted attributes on <
${element}>'); |
184 _removeNode(node, parent); | 180 _removeNode(node, parent); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 case Node.COMMENT_NODE: | 219 case Node.COMMENT_NODE: |
224 case Node.DOCUMENT_FRAGMENT_NODE: | 220 case Node.DOCUMENT_FRAGMENT_NODE: |
225 case Node.TEXT_NODE: | 221 case Node.TEXT_NODE: |
226 case Node.CDATA_SECTION_NODE: | 222 case Node.CDATA_SECTION_NODE: |
227 break; | 223 break; |
228 default: | 224 default: |
229 _removeNode(node, parent); | 225 _removeNode(node, parent); |
230 } | 226 } |
231 } | 227 } |
232 } | 228 } |
OLD | NEW |