Skip to content

Commit

Permalink
Added new test data cases, simplified regular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
psmyrek committed Mar 16, 2021
1 parent e36175e commit 368cdbc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/ckeditor5-font/src/fontsize/fontsizeediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
/**
Expand Down
6 changes: 4 additions & 2 deletions packages/ckeditor5-image/src/autoimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions packages/ckeditor5-image/tests/autoimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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, '<paragraph>[]</paragraph>' );
pasteHtml( editor, invalidURL );
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-media-embed/src/automediaembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-media-embed/tests/automediaembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<paragraph>[]</paragraph>' );
pasteHtml( editor, invalidURL );
Expand Down

0 comments on commit 368cdbc

Please sign in to comment.