This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ export default class Template {
245245 for ( const child of def . children ) {
246246 if ( isView ( child ) ) {
247247 yield child ;
248- } else {
248+ } else if ( isTemplate ( child ) ) {
249249 yield * search ( child ) ;
250250 }
251251 }
Original file line number Diff line number Diff line change @@ -1533,6 +1533,32 @@ describe( 'Template', () => {
15331533
15341534 expect ( Array . from ( template . getViews ( ) ) ) . to . have . members ( [ viewA , viewB , viewC ] ) ;
15351535 } ) ;
1536+
1537+ // https://github.com/ckeditor/ckeditor5-ui/issues/337
1538+ it ( 'does not traverse non–Template children' , ( ) => {
1539+ const viewA = new View ( ) ;
1540+ const viewB = new View ( ) ;
1541+ const viewC = new View ( ) ;
1542+
1543+ const template = new Template ( {
1544+ tag : 'div' ,
1545+ children : [
1546+ viewA ,
1547+ ]
1548+ } ) ;
1549+
1550+ // Technically, this kind of child is invalid but the aim of this test is to
1551+ // check if the generator will accidentally traverse non–Template objects
1552+ // like native HTML elements, which also have "children" property. It could happen
1553+ // because it is possible to pass HTML elements directly to the templateDefinition.
1554+ template . children . push ( {
1555+ children : [ viewB ]
1556+ } ) ;
1557+
1558+ template . children . push ( viewC ) ;
1559+
1560+ expect ( Array . from ( template . getViews ( ) ) ) . to . have . members ( [ viewA , viewC ] ) ;
1561+ } ) ;
15361562 } ) ;
15371563
15381564 describe ( 'bind()' , ( ) => {
You can’t perform that action at this time.
0 commit comments