Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($compile): handle elements with no childNodes property
Browse files Browse the repository at this point in the history
see the test for more details
  • Loading branch information
IgorMinar committed Feb 24, 2013
1 parent 509ec74 commit bec614f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <object>),
// 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('<div>{{1+2}}</div>');
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(
Expand Down

0 comments on commit bec614f

Please sign in to comment.