-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($compile): remove comment nodes from templates before asserting single root node #9215
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1481,7 +1481,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
if (jqLiteIsTextNode(directiveValue)) { | ||
$template = []; | ||
} else { | ||
$template = jqLite(wrapTemplate(directive.templateNamespace, trim(directiveValue))); | ||
$template = removeComments(jqLite(wrapTemplate(directive.templateNamespace, trim(directiveValue)))); | ||
} | ||
compileNode = $template[0]; | ||
|
||
|
@@ -1951,7 +1951,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
if (jqLiteIsTextNode(content)) { | ||
$template = []; | ||
} else { | ||
$template = jqLite(wrapTemplate(templateNamespace, trim(content))); | ||
$template = removeComments(jqLite(wrapTemplate(templateNamespace, trim(content)))); | ||
} | ||
compileNode = $template[0]; | ||
|
||
|
@@ -2362,3 +2362,16 @@ function tokenDifference(str1, str2) { | |
} | ||
return values; | ||
} | ||
|
||
function removeComments(jqNodes) { | ||
var i = jqNodes.length; | ||
var splice = Array.prototype.splice; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a global There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like the global |
||
|
||
if (i <= 1) return jqNodes; | ||
|
||
while (i--) { | ||
var node = jqNodes[i]; | ||
if (node.nodeType === 8) splice.call(jqNodes, i, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't use single line |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't suppose that splice will update the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http://jsfiddle.net/dku33bfy/ at least in modern browsers we're good there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting. thanks for checking |
||
return jqNodes; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how many more function calls can we make in this line of code? :)