@@ -1352,6 +1352,22 @@ describe('$compile', function() {
1352
1352
} ) ;
1353
1353
} ) ;
1354
1354
1355
+ it ( 'should ignore whitespace betwee comment and root node when replacing with a template' , function ( ) {
1356
+ module ( function ( ) {
1357
+ directive ( 'replaceWithWhitespace' , valueFn ( {
1358
+ replace : true ,
1359
+ template : '<!-- ignored comment --> <p>Hello, world!</p> <!-- ignored comment-->'
1360
+ } ) ) ;
1361
+ } ) ;
1362
+ inject ( function ( $compile , $rootScope ) {
1363
+ expect ( function ( ) {
1364
+ element = $compile ( '<div><div replace-with-whitespace></div></div>' ) ( $rootScope ) ;
1365
+ } ) . not . toThrow ( ) ;
1366
+ expect ( element . find ( 'p' ) . length ) . toBe ( 1 ) ;
1367
+ expect ( element . find ( 'p' ) . text ( ) ) . toBe ( 'Hello, world!' ) ;
1368
+ } ) ;
1369
+ } ) ;
1370
+
1355
1371
it ( 'should keep prototype properties on directive' , function ( ) {
1356
1372
module ( function ( ) {
1357
1373
function DirectiveClass ( ) {
@@ -2080,6 +2096,18 @@ describe('$compile', function() {
2080
2096
$compile ( '<p template></p>' ) ;
2081
2097
$rootScope . $apply ( ) ;
2082
2098
expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
2099
+
2100
+ // comments are ok
2101
+ $templateCache . put ( 'template.html' , '<!-- oh hi --><div></div> \n' ) ;
2102
+ $compile ( '<p template></p>' ) ;
2103
+ $rootScope . $apply ( ) ;
2104
+ expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
2105
+
2106
+ // white space around comments is ok
2107
+ $templateCache . put ( 'template.html' , ' <!-- oh hi --> <div></div> <!-- oh hi -->\n' ) ;
2108
+ $compile ( '<p template></p>' ) ;
2109
+ $rootScope . $apply ( ) ;
2110
+ expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
2083
2111
} ) ;
2084
2112
} ) ;
2085
2113
@@ -2291,6 +2319,26 @@ describe('$compile', function() {
2291
2319
} ) ;
2292
2320
} ) ;
2293
2321
2322
+ it ( 'should ignore whitespace between comment and root node when replacing with a templateUrl' , function ( ) {
2323
+ module ( function ( ) {
2324
+ directive ( 'replaceWithWhitespace' , valueFn ( {
2325
+ replace : true ,
2326
+ templateUrl : 'templateWithWhitespace.html'
2327
+ } ) ) ;
2328
+ } ) ;
2329
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
2330
+ $httpBackend . whenGET ( 'templateWithWhitespace.html' ) .
2331
+ respond ( '<!-- ignored comment --> <p>Hello, world!</p> <!-- ignored comment-->' ) ;
2332
+ expect ( function ( ) {
2333
+ element = $compile ( '<div><div replace-with-whitespace></div></div>' ) ( $rootScope ) ;
2334
+ } ) . not . toThrow ( ) ;
2335
+ $httpBackend . flush ( ) ;
2336
+ expect ( element . find ( 'p' ) . length ) . toBe ( 1 ) ;
2337
+ expect ( element . find ( 'p' ) . text ( ) ) . toBe ( 'Hello, world!' ) ;
2338
+ } ) ;
2339
+ } ) ;
2340
+
2341
+
2294
2342
it ( 'should keep prototype properties on sync version of async directive' , function ( ) {
2295
2343
module ( function ( ) {
2296
2344
function DirectiveClass ( ) {
0 commit comments