Skip to content

Commit

Permalink
Review fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksymilian Barnaś committed Feb 9, 2022
1 parent 612382d commit 8e3fede
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
8 changes: 3 additions & 5 deletions packages/ckeditor5-engine/src/view/domconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ export default class DomConverter {
* @returns {Boolean}
*/
_shouldRenameElement( elementName ) {
const name = elementName.toLocaleLowerCase();
const name = elementName.toLowerCase();

return this.renderingMode === 'editing' && UNSAFE_ELEMENTS.includes( name );
}
Expand Down Expand Up @@ -1662,15 +1662,13 @@ function _logUnsafeElement( elementName ) {
* the `<script>` element was renamed to `<span data-ck-unsafe-element="script"></span>`.
*
* @error domconverter-unsafe-script-element-detected
* that was renamed.
*/

/**
* The {@link module:engine/view/domconverter~DomConverter} detected a `<style>` element that may affect the editing experience.
* To avoid this, the `<style>` element was renamed to `<span data-ck-unsafe-element="style"></span>`.
* While rendering the editor content, the {@link module:engine/view/domconverter~DomConverter} detected a `<style>` element that may affect
* the editing experience. To avoid this, the `<style>` element was replaced with `<span data-ck-unsafe-element="style"></span>`.
*
* @error domconverter-unsafe-style-element-detected
* that was renamed.
*/

/**
Expand Down
17 changes: 8 additions & 9 deletions packages/ckeditor5-html-support/tests/integrations/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-util

describe( 'StyleElementSupport', () => {
const STYLE = 'div { color: red; }';
const CODE_CPP = 'cout << "Hello World" << endl;';

let editor, model, editorElement, dataFilter, warnStub;

Expand Down Expand Up @@ -52,43 +51,43 @@ describe( 'StyleElementSupport', () => {
it( 'should allow attributes', () => {
dataFilter.allowAttributes( { name: 'style', attributes: [ 'type', 'nonce' ] } );

editor.setData( `<p>Foo</p><style type="c++" nonce="qwerty">${ CODE_CPP }</style>` );
editor.setData( `<p>Foo</p><style type="c++" nonce="qwerty">${ STYLE }</style>` );

expect( getModelDataWithAttributes( model, { withoutSelection: true } ) ).to.deep.equal( {
data: `<paragraph>Foo</paragraph><htmlStyle htmlAttributes="(1)" htmlContent="${ CODE_CPP }"></htmlStyle>`,
data: `<paragraph>Foo</paragraph><htmlStyle htmlAttributes="(1)" htmlContent="${ STYLE }"></htmlStyle>`,
attributes: {
1: {
attributes: {
nonce: 'qwerty',
type: 'c++'
}
},
2: CODE_CPP
2: STYLE
}
} );

expect( editor.getData() ).to.equal( `<p>Foo</p><style type="c++" nonce="qwerty">${ CODE_CPP }</style>` );
expect( editor.getData() ).to.equal( `<p>Foo</p><style type="c++" nonce="qwerty">${ STYLE }</style>` );
} );

it( 'should disallow attributes', () => {
dataFilter.allowAttributes( { name: 'style', attributes: true } );
dataFilter.disallowAttributes( { name: 'style', attributes: 'nonce' } );

editor.setData( `<p>Foo</p><style type="c++" nonce="qwerty">${ CODE_CPP }</style>` );
editor.setData( `<p>Foo</p><style type="c++" nonce="qwerty">${ STYLE }</style>` );

expect( getModelDataWithAttributes( model, { withoutSelection: true } ) ).to.deep.equal( {
data: `<paragraph>Foo</paragraph><htmlStyle htmlAttributes="(1)" htmlContent="${ CODE_CPP }"></htmlStyle>`,
data: `<paragraph>Foo</paragraph><htmlStyle htmlAttributes="(1)" htmlContent="${ STYLE }"></htmlStyle>`,
attributes: {
1: {
attributes: {
type: 'c++'
}
},
2: CODE_CPP
2: STYLE
}
} );

expect( editor.getData() ).to.equal( `<p>Foo</p><style type="c++">${ CODE_CPP }</style>` );
expect( editor.getData() ).to.equal( `<p>Foo</p><style type="c++">${ STYLE }</style>` );
} );

describe( 'element position', () => {
Expand Down

0 comments on commit 8e3fede

Please sign in to comment.