@@ -1364,6 +1364,22 @@ describe('$compile', function() {
13641364 } ) ;
13651365 } ) ;
13661366
1367+ it ( 'should ignore whitespace betwee comment and root node when replacing with a template' , function ( ) {
1368+ module ( function ( ) {
1369+ directive ( 'replaceWithWhitespace' , valueFn ( {
1370+ replace : true ,
1371+ template : '<!-- ignored comment --> <p>Hello, world!</p> <!-- ignored comment-->'
1372+ } ) ) ;
1373+ } ) ;
1374+ inject ( function ( $compile , $rootScope ) {
1375+ expect ( function ( ) {
1376+ element = $compile ( '<div><div replace-with-whitespace></div></div>' ) ( $rootScope ) ;
1377+ } ) . not . toThrow ( ) ;
1378+ expect ( element . find ( 'p' ) . length ) . toBe ( 1 ) ;
1379+ expect ( element . find ( 'p' ) . text ( ) ) . toBe ( 'Hello, world!' ) ;
1380+ } ) ;
1381+ } ) ;
1382+
13671383 it ( 'should keep prototype properties on directive' , function ( ) {
13681384 module ( function ( ) {
13691385 function DirectiveClass ( ) {
@@ -2092,6 +2108,18 @@ describe('$compile', function() {
20922108 $compile ( '<p template></p>' ) ;
20932109 $rootScope . $apply ( ) ;
20942110 expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
2111+
2112+ // comments are ok
2113+ $templateCache . put ( 'template.html' , '<!-- oh hi --><div></div> \n' ) ;
2114+ $compile ( '<p template></p>' ) ;
2115+ $rootScope . $apply ( ) ;
2116+ expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
2117+
2118+ // white space around comments is ok
2119+ $templateCache . put ( 'template.html' , ' <!-- oh hi --> <div></div> <!-- oh hi -->\n' ) ;
2120+ $compile ( '<p template></p>' ) ;
2121+ $rootScope . $apply ( ) ;
2122+ expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
20952123 } ) ;
20962124 } ) ;
20972125
@@ -2303,6 +2331,26 @@ describe('$compile', function() {
23032331 } ) ;
23042332 } ) ;
23052333
2334+ it ( 'should ignore whitespace between comment and root node when replacing with a templateUrl' , function ( ) {
2335+ module ( function ( ) {
2336+ directive ( 'replaceWithWhitespace' , valueFn ( {
2337+ replace : true ,
2338+ templateUrl : 'templateWithWhitespace.html'
2339+ } ) ) ;
2340+ } ) ;
2341+ inject ( function ( $compile , $rootScope , $httpBackend ) {
2342+ $httpBackend . whenGET ( 'templateWithWhitespace.html' ) .
2343+ respond ( '<!-- ignored comment --> <p>Hello, world!</p> <!-- ignored comment-->' ) ;
2344+ expect ( function ( ) {
2345+ element = $compile ( '<div><div replace-with-whitespace></div></div>' ) ( $rootScope ) ;
2346+ } ) . not . toThrow ( ) ;
2347+ $httpBackend . flush ( ) ;
2348+ expect ( element . find ( 'p' ) . length ) . toBe ( 1 ) ;
2349+ expect ( element . find ( 'p' ) . text ( ) ) . toBe ( 'Hello, world!' ) ;
2350+ } ) ;
2351+ } ) ;
2352+
2353+
23062354 it ( 'should keep prototype properties on sync version of async directive' , function ( ) {
23072355 module ( function ( ) {
23082356 function DirectiveClass ( ) {
0 commit comments