@@ -1364,6 +1364,22 @@ describe('$compile', function() {
1364
1364
} ) ;
1365
1365
} ) ;
1366
1366
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
+
1367
1383
it ( 'should keep prototype properties on directive' , function ( ) {
1368
1384
module ( function ( ) {
1369
1385
function DirectiveClass ( ) {
@@ -2092,6 +2108,18 @@ describe('$compile', function() {
2092
2108
$compile ( '<p template></p>' ) ;
2093
2109
$rootScope . $apply ( ) ;
2094
2110
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 ( [ ] ) ;
2095
2123
} ) ;
2096
2124
} ) ;
2097
2125
@@ -2303,6 +2331,26 @@ describe('$compile', function() {
2303
2331
} ) ;
2304
2332
} ) ;
2305
2333
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
+
2306
2354
it ( 'should keep prototype properties on sync version of async directive' , function ( ) {
2307
2355
module ( function ( ) {
2308
2356
function DirectiveClass ( ) {
0 commit comments