diff --git a/packages/ckeditor5-engine/src/view/styles/utils.js b/packages/ckeditor5-engine/src/view/styles/utils.js index eb2a123661c..2dc5d4ec531 100644 --- a/packages/ckeditor5-engine/src/view/styles/utils.js +++ b/packages/ckeditor5-engine/src/view/styles/utils.js @@ -86,7 +86,7 @@ export function isLineStyle( string ) { return lineStyleValues.includes( string ); } -const lengthRegExp = /^([+-]?[0-9]*[.]?[0-9]+(px|cm|mm|in|pc|pt|ch|em|ex|rem|vh|vw|vmin|vmax)|0)$/; +const lengthRegExp = /^([+-]?[0-9]*([.][0-9]+)?(px|cm|mm|in|pc|pt|ch|em|ex|rem|vh|vw|vmin|vmax)|0)$/; /** * Checks if string contains [length](https://developer.mozilla.org/en-US/docs/Web/CSS/length) CSS value. @@ -98,7 +98,7 @@ export function isLength( string ) { return lengthRegExp.test( string ); } -const PERCENTAGE_VALUE_REGEXP = /^[+-]?[0-9]*[.]?[0-9]+%$/; +const PERCENTAGE_VALUE_REGEXP = /^[+-]?[0-9]*([.][0-9]+)?%$/; /** * Checks if string contains [percentage](https://developer.mozilla.org/en-US/docs/Web/CSS/percentage) CSS value. diff --git a/packages/ckeditor5-engine/tests/view/styles/utils.js b/packages/ckeditor5-engine/tests/view/styles/utils.js index 7fd7ec579ac..66c229507a7 100644 --- a/packages/ckeditor5-engine/tests/view/styles/utils.js +++ b/packages/ckeditor5-engine/tests/view/styles/utils.js @@ -181,6 +181,11 @@ describe( 'Styles utils', () => { isLength ); } ); + + // s/ckeditor5/3 + it( 'should handle invalid values with repeated characters', () => { + expect( isLength( '9'.repeat( 1000000 ) ) ).to.be.false; + } ); } ); describe( 'isPercentage()', () => { @@ -191,6 +196,11 @@ describe( 'Styles utils', () => { it( 'returns false for not a percentage values', () => { testValues( [ '0', '1px', '1000px', '1.1px', '345.457px', '.457px' ], value => !isPercentage( value ) ); } ); + + // s/ckeditor5/3 + it( 'should handle invalid values with repeated characters', () => { + expect( isPercentage( '9'.repeat( 1000000 ) ) ).to.be.false; + } ); } ); describe( 'getBoxSidesShorthandValue()', () => { diff --git a/packages/ckeditor5-font/src/fontsize/fontsizeediting.js b/packages/ckeditor5-font/src/fontsize/fontsizeediting.js index fab82d822dc..7ca6da26e6e 100644 --- a/packages/ckeditor5-font/src/fontsize/fontsizeediting.js +++ b/packages/ckeditor5-font/src/fontsize/fontsizeediting.js @@ -109,7 +109,7 @@ export default class FontSizeEditing extends Plugin { const editor = this.editor; // If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration. - const presets = definition.model.values.filter( value => !String( value ).match( /[\d.]+[\w%]+/ ) ); + const presets = definition.model.values.filter( value => !String( value ).match( /^[\d.]+[a-zA-Z%]+$/ ) ); if ( presets.length ) { /** diff --git a/packages/ckeditor5-image/src/autoimage.js b/packages/ckeditor5-image/src/autoimage.js index 51b48d300b6..b5c16894b68 100644 --- a/packages/ckeditor5-image/src/autoimage.js +++ b/packages/ckeditor5-image/src/autoimage.js @@ -16,8 +16,8 @@ import { global } from 'ckeditor5/src/utils'; import { insertImage } from './image/utils'; // Implements the pattern: http(s)://(www.)example.com/path/to/resource.ext?query=params&maybe=too. -const IMAGE_URL_REGEXP = new RegExp( String( /^(http(s)?:\/\/)?[\w-]+(\.[\w-]+)+[\w._~:/?#[\]@!$&'()*+,;=%-]+/.source + - /\.(jpg|jpeg|png|gif|ico|webp|JPG|JPEG|PNG|GIF|ICO|WEBP)\??[\w._~:/#[\]@!$&'()*+,;=%-]*$/.source ) ); +const IMAGE_URL_REGEXP = new RegExp( String( /^(http(s)?:\/\/)?[\w-]+\.[\w._~:/?#[\]@!$&'()*+,;=%-]+/.source + + /\.(jpg|jpeg|png|gif|ico|webp|JPG|JPEG|PNG|GIF|ICO|WEBP)(\?[\w._~:/#[\]@!$&'()*+,;=%-]*)?$/.source ) ); /** * The auto-image plugin. It recognizes image links in the pasted content and embeds diff --git a/packages/ckeditor5-image/tests/autoimage.js b/packages/ckeditor5-image/tests/autoimage.js index 01cbe12ebe2..3ebabf53a14 100644 --- a/packages/ckeditor5-image/tests/autoimage.js +++ b/packages/ckeditor5-image/tests/autoimage.js @@ -153,6 +153,20 @@ describe( 'AutoImage - integration', () => { ); } ); } + + // s/ckeditor5/3 + it( 'should handle invalid URL with repeated characters', () => { + const invalidURL = 'a.' + 'a'.repeat( 1000000 ); + + setData( editor.model, '[]' ); + pasteHtml( editor, invalidURL ); + + clock.tick( 100 ); + + expect( getData( editor.model ) ).to.equal( + `${ invalidURL }[]` + ); + } ); } ); it( 'works for URL that was pasted as a link', () => { diff --git a/packages/ckeditor5-list/src/converters.js b/packages/ckeditor5-list/src/converters.js index 4722f5553fa..404e193faf5 100644 --- a/packages/ckeditor5-list/src/converters.js +++ b/packages/ckeditor5-list/src/converters.js @@ -445,12 +445,12 @@ export function cleanListItem( evt, data, conversionApi ) { if ( child.is( '$text' ) ) { // If this is the first node and it's a text node, left-trim it. if ( firstNode ) { - child._data = child.data.replace( /^\s+/, '' ); + child._data = child.data.trimStart(); } // If this is the last text node before