Skip to content

Commit

Permalink
Merge branch 't/13419'
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Jul 7, 2015
2 parents 486b001 + 23faec1 commit e235295
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
68 changes: 37 additions & 31 deletions plugins/autolink/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} );
}
} );
} )();
8 changes: 8 additions & 0 deletions tests/plugins/autolink/autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit e235295

Please sign in to comment.