From 368cdbc2abae39b1adaa24a51b0a9be22e0119a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Smyrek?= Date: Tue, 16 Mar 2021 08:19:41 +0100 Subject: [PATCH] Added new test data cases, simplified regular expressions --- packages/ckeditor5-font/src/fontsize/fontsizeediting.js | 2 +- packages/ckeditor5-image/src/autoimage.js | 6 ++++-- packages/ckeditor5-image/tests/autoimage.js | 7 +++++-- packages/ckeditor5-media-embed/src/automediaembed.js | 2 +- packages/ckeditor5-media-embed/tests/automediaembed.js | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/ckeditor5-font/src/fontsize/fontsizeediting.js b/packages/ckeditor5-font/src/fontsize/fontsizeediting.js index 7ca6da26e6e..cd91d98092c 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.]+[a-zA-Z%]+$/ ) ); + const presets = definition.model.values.filter( value => !String( value ).match( /[\d.][\w%]+/ ) ); if ( presets.length ) { /** diff --git a/packages/ckeditor5-image/src/autoimage.js b/packages/ckeditor5-image/src/autoimage.js index b5c16894b68..a7916c1cedf 100644 --- a/packages/ckeditor5-image/src/autoimage.js +++ b/packages/ckeditor5-image/src/autoimage.js @@ -16,8 +16,10 @@ 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._~:/?#[\]@!$&'()*+,;=%-]+/.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)/.source + + /(\?[\w.~:/[\]@!$&'()*+,;=%-]*)?/.source + + /(#[\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 3ebabf53a14..b661cc474de 100644 --- a/packages/ckeditor5-image/tests/autoimage.js +++ b/packages/ckeditor5-image/tests/autoimage.js @@ -111,7 +111,10 @@ describe( 'AutoImage - integration', () => { 'http://example.com/image.JPG', 'http://example.com%20Fimage.png', 'http://example.com/image.png?foo=bar', - 'http://example.com/image.png#foo' + 'http://example.com/image.png#', + 'http://example.com/image.png#foo', + 'http://example.com/image.png?foo=bar#', + 'http://example.com/image.png?foo=bar#baz' ]; for ( const supportedURL of supportedURLs ) { @@ -156,7 +159,7 @@ describe( 'AutoImage - integration', () => { // s/ckeditor5/3 it( 'should handle invalid URL with repeated characters', () => { - const invalidURL = 'a.' + 'a'.repeat( 1000000 ); + const invalidURL = 'a.' + 'a'.repeat( 100000 ); setData( editor.model, '[]' ); pasteHtml( editor, invalidURL ); diff --git a/packages/ckeditor5-media-embed/src/automediaembed.js b/packages/ckeditor5-media-embed/src/automediaembed.js index d8e330db3f0..b523ebca5fd 100644 --- a/packages/ckeditor5-media-embed/src/automediaembed.js +++ b/packages/ckeditor5-media-embed/src/automediaembed.js @@ -16,7 +16,7 @@ import { global } from 'ckeditor5/src/utils'; import MediaEmbedEditing from './mediaembedediting'; import { insertMedia } from './utils'; -const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w.-][\w\-._~:/?#[\]@!$&'()*+,;=%]+$/; +const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w.-][\w-.~:/?#[\]@!$&'()*+,;=%]+$/; /** * The auto-media embed plugin. It recognizes media links in the pasted content and embeds diff --git a/packages/ckeditor5-media-embed/tests/automediaembed.js b/packages/ckeditor5-media-embed/tests/automediaembed.js index aaeed2dda75..34b3c705d4d 100644 --- a/packages/ckeditor5-media-embed/tests/automediaembed.js +++ b/packages/ckeditor5-media-embed/tests/automediaembed.js @@ -329,7 +329,7 @@ describe( 'AutoMediaEmbed - integration', () => { // s/ckeditor5/3 it( 'should handle invalid URL with repeated characters', () => { - const invalidURL = 'a.' + 'a'.repeat( 1000000 ) + '^'; + const invalidURL = 'a.' + 'a'.repeat( 100000 ) + '^'; setData( editor.model, '[]' ); pasteHtml( editor, invalidURL );