Skip to content
Permalink
Browse files

Merge branch 't/13419'

  • Loading branch information...
oleq committed Jul 7, 2015
2 parents 486b001 + 23faec1 commit e235295f7152524002991efcd5c00645187644ec
Showing with 46 additions and 31 deletions.
  1. +1 −0 CHANGES.md
  2. +37 −31 plugins/autolink/plugin.js
  3. +8 −0 tests/plugins/autolink/autolink.js
@@ -9,6 +9,7 @@ Fixed Issues:
* [#13434](http://dev.ckeditor.com/ticket/13434): [IE8-9] Fixed: One drag&drop operation may affect following ones.
* [#13129](http://dev.ckeditor.com/ticket/13129) Fixed: Block widget blurred after drop followed by undo.
* [#13468](http://dev.ckeditor.com/ticket/13468): [IE] Fixed: Binding drag&drop `dataTransfer` does not work if `text` data was set in the meantime.
* [#13419](http://dev.ckeditor.com/ticket/13419): Fixed: [Auto Link](http://ckeditor.com/addon/autolink) plugin does not encode double quotes in URLs.

## CKEditor 4.5.1

@@ -3,34 +3,40 @@
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/

'use strict';

CKEDITOR.plugins.add( 'autolink', {
requires: 'clipboard',

init: function( editor ) {
editor.on( 'paste', function( evt ) {
var data = evt.data.dataValue;

if ( evt.data.dataTransfer.getTransferType( editor ) == CKEDITOR.DATA_TRANSFER_INTERNAL ) {
return;
}

// If we found "<" it means that most likely there's some tag and we don't want to touch it.
if ( data.indexOf( '<' ) > -1 ) {
return;
}

// Regex by Imme Emosol.
data = data.replace( /^(https?|ftp):\/\/(-\.)?([^\s\/?\.#-]+\.?)+(\/[^\s]*)?[^\s\.,]$/ig , '<a href="$&">$&</a>' );

// If link was discovered, change the type to 'html'. This is important e.g. when pasting plain text in Chrome
// where real type is correctly recognized.
if ( data != evt.data.dataValue ) {
evt.data.type = 'html';
}

evt.data.dataValue = data;
} );
}
} );
( function() {
'use strict';

// Regex by Imme Emosol.
var validUrlRegex = /^(https?|ftp):\/\/(-\.)?([^\s\/?\.#-]+\.?)+(\/[^\s]*)?[^\s\.,]$/ig,
doubleQuoteRegex = /"/g;

CKEDITOR.plugins.add( 'autolink', {
requires: 'clipboard',

init: function( editor ) {
editor.on( 'paste', function( evt ) {
var data = evt.data.dataValue;

if ( evt.data.dataTransfer.getTransferType( editor ) == CKEDITOR.DATA_TRANSFER_INTERNAL ) {
return;
}

// If we found "<" it means that most likely there's some tag and we don't want to touch it.
if ( data.indexOf( '<' ) > -1 ) {
return;
}

// #13419
data = data.replace( validUrlRegex , '<a href="' + data.replace( doubleQuoteRegex, '%22' ) + '">$&</a>' );

// If link was discovered, change the type to 'html'. This is important e.g. when pasting plain text in Chrome
// where real type is correctly recognized.
if ( data != evt.data.dataValue ) {
evt.data.type = 'html';
}

evt.data.dataValue = data;
} );
}
} );
} )();
@@ -47,6 +47,14 @@ bender.test( {
}
},

// #13419
'test link with quotation marks': function() {
var pastedText = 'https://foo.bar/?bam="bom"',
expected = '<a href="https://foo.bar/?bam=%22bom%22">https://foo.bar/?bam="bom"</a>';

assertPasteEvent( this.editor, { dataValue: pastedText }, { dataValue: expected, type: 'html' } );
},

'test link with text after': function() {
var pastedText = 'https://placekitten.com/g/210/300 nope';

0 comments on commit e235295

Please sign in to comment.
You can’t perform that action at this time.