From bec614fd90c48c3921a4b659912008574e553b40 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sat, 23 Feb 2013 22:54:35 -0800 Subject: fix($compile): handle elements with no childNodes property see the test for more details --- src/ng/compile.js | 2 +- test/ng/compileSpec.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 11a86f3f..113bacc5 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -433,7 +433,7 @@ function $CompileProvider($provide) { ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement) : null; - childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || !nodeList[i].childNodes.length) + childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || !nodeList[i].childNodes || !nodeList[i].childNodes.length) ? null : compileNodes(nodeList[i].childNodes, nodeLinkFn ? nodeLinkFn.transclude : transcludeFn); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index d2eddafc..74b1e9e3 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -178,6 +178,28 @@ describe('$compile', function() { expect(calcCacheSize()).toEqual(0); }); + + it('should not blow up when elements with no childNodes property are compiled', inject( + function($compile, $rootScope) { + // it turns out that when a browser plugin is bound to an DOM element (typically ), + // the plugin's context rather than the usual DOM apis are exposed on this element, so + // childNodes might not exist. + if (msie < 9) return; + + element = jqLite('
{{1+2}}
'); + element[0].childNodes[1] = {nodeType: 3, nodeName: 'OBJECT', textContent: 'fake node'}; + + if (!element[0].childNodes[1]) return; //browser doesn't support this kind of mocking + expect(element[0].childNodes[1].textContent).toBe('fake node'); + + $compile(element)($rootScope); + $rootScope.$apply(); + + // object's children can't be compiled in this case, so we expect them to be raw + expect(element.html()).toBe("3"); + })); + + describe('multiple directives per element', function() { it('should allow multiple directives per element', inject(function($compile, $rootScope, log){ element = $compile( -- cgit v1.2.3