Skip to content

Commit

Permalink
Merge pull request #11929 from ckeditor/ck/11879
Browse files Browse the repository at this point in the history
Fix (engine): The view element renderUnsafeAttributes option should not be lost for an AttributeElements. Closes #11879.
  • Loading branch information
arkflpc authored Jun 21, 2022
2 parents 4166789 + 414683a commit 2fd7f85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/ckeditor5-engine/src/view/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ export default class Element extends Node {
// is changed by e.g. toWidget() function from ckeditor5-widget. Perhaps this should be one of custom props.
cloned.getFillerOffset = this.getFillerOffset;

// Clone unsafe attributes list.
cloned._unsafeAttributesToRender = this._unsafeAttributesToRender;

return cloned;
}

Expand Down
23 changes: 22 additions & 1 deletion packages/ckeditor5-engine/tests/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4062,7 +4062,7 @@ describe( 'Renderer', () => {
expect( normalizeHtml( domRoot.innerHTML ) ).to.equal( '<p data-ck-unsafe-attribute-onclick="test">foo</p>' );
} );

it( 'should rename attributes that can affect editing pipeline unless permitted when the element was created', () => {
it( 'should rename attributes that can affect editing pipeline unless permitted when the container element was created', () => {
view.change( writer => {
const containerElement = writer.createContainerElement( 'p', {
onclick: 'foo',
Expand All @@ -4083,6 +4083,27 @@ describe( 'Renderer', () => {
);
} );

it( 'should rename attributes that can affect editing pipeline unless permitted when an attribute element was created', () => {
view.change( writer => {
const attributeElement = writer.createAttributeElement( 'span', {
onclick: 'foo',
onkeydown: 'bar'
}, {
renderUnsafeAttributes: [ 'onclick' ]
} );

writer.insert( writer.createPositionAt( view.document.getRoot(), 'start' ), writer.createText( 'baz' ) );
writer.wrap( writer.createRangeIn( view.document.getRoot() ), attributeElement );
} );

view.forceRender();

expect( getViewData( view ) ).to.equal( '<span onclick="foo" onkeydown="bar">baz</span>' );
expect( normalizeHtml( domRoot.innerHTML ) ).to.equal(
'<span data-ck-unsafe-attribute-onkeydown="bar" onclick="foo">baz</span>'
);
} );

it( 'should rename attributes that can not be rendered in the editing pipeline', () => {
setViewData( view,
'<container:p>' +
Expand Down

0 comments on commit 2fd7f85

Please sign in to comment.