Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 894bad0

Browse files
authored
Merge pull request #338 from ckeditor/t/337
Fix: `Template#getViews` generator should not traverse native HTML elements. Closes #337. Closes ckeditor/ckeditor5#657.
2 parents 823120b + 04628a9 commit 894bad0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

tests/template.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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()', () => {

0 commit comments

Comments
 (0)