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

Commit

Permalink
fix($compile): do not wrap empty root text nodes in spans
Browse files Browse the repository at this point in the history
Closes #1059
  • Loading branch information
petebacondarwin authored and IgorMinar committed Jan 17, 2013
1 parent 7e74601 commit 49f9e4c
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -318,7 +318,7 @@ function $CompileProvider($provide) {
// We can not compile top level text elements since text nodes can be merged and we will
// not be able to attach scope data to them, so we will wrap them in <span>
forEach($compileNodes, function(node, index){
if (node.nodeType == 3 /* text node */) {
if (node.nodeType == 3 /* text node */ && node.nodeValue.match(/\S+/) /* non-empty */ ) {
$compileNodes[index] = jqLite(node).wrap('<span></span>').parent()[0];
}
});
Expand Down
13 changes: 13 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ describe('$compile', function() {
expect(element.find('span').text()).toEqual('A<a>B</a>C');
}));


it('should not wrap root whitespace text nodes in spans', function() {
element = jqLite(
'<div> <div>A</div>\n '+ // The spaces and newlines here should not get wrapped
'<div>B</div>C\t\n '+ // The "C", tabs and spaces here will be wrapped
'</div>');
$compile(element.contents())($rootScope);
var spans = element.find('span');
expect(spans.length).toEqual(1);
expect(spans.text().indexOf('C')).toEqual(0);
});


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 49f9e4c

Please sign in to comment.