Skip to content
Permalink
Browse files

Merge branch 't/13420'

  • Loading branch information...
oleq committed Jul 14, 2015
2 parents fa71d86 + 8ca35b7 commit 2b303281ee67a5fce7a567bd56f90aa0e2d6776b
Showing with 55 additions and 16 deletions.
  1. +1 −0 CHANGES.md
  2. +6 −16 plugins/autoembed/plugin.js
  3. +48 −0 tests/plugins/autoembed/autoembed.js
@@ -16,6 +16,7 @@ Fixed Issues:
* [#13422](http://dev.ckeditor.com/ticket/13422): Fixed: A monospaced font should be used in the `<textarea>` holding editor's config in the Toolbar Configurator.
* [#11616](http://dev.ckeditor.com/ticket/11616): [Chrome] Fixed: Resizing the editor while it's not displayed breaks the editable. Fixed also [#9160](http://dev.ckeditor.com/ticket/9160) and [#9715](http://dev.ckeditor.com/ticket/9715).
* [#13397](http://dev.ckeditor.com/ticket/13397): Fixed: Drag&drop a widget inside its nested widget crashes the editor.
* [#13420](http://dev.ckeditor.com/ticket/13420): Fixed: [Auto Media Embed](http://ckeditor.com/addon/autoembed) plugin ignores encoded characters in URL parameters.

## CKEditor 4.5.1

@@ -6,6 +6,8 @@
'use strict';

( function() {
var validLinkRegExp = /^<a[^>]+href="([^"]+)"[^>]*>([^<]+)<\/a>$/i;

CKEDITOR.plugins.add( 'autoembed', {
requires: 'autolink,undo',

@@ -17,25 +19,13 @@
return;
}

var data = evt.data.dataValue,
parsedData,
link;
var match = evt.data.dataValue.match( validLinkRegExp );

// Expecting exactly one <a> tag spanning the whole pasted content.
if ( data.match( /^<a [^<]+<\/a>$/i ) ) {
parsedData = CKEDITOR.htmlParser.fragment.fromHtml( data );

// Embed only links with a single text node with a href attr which equals its text.
if ( parsedData.children.length != 1 )
return;

link = parsedData.children[ 0 ];

if ( link.type == CKEDITOR.NODE_ELEMENT && link.getHtml() == link.attributes.href ) {
evt.data.dataValue = '<a data-cke-autoembed="' + ( ++currentId ) + '"' + data.substr( 2 );
}
// The tag has to have same href as content.
if ( match != null && decodeURI( match[ 1 ] ) == decodeURI( match[ 2 ] ) ) {
evt.data.dataValue = '<a data-cke-autoembed="' + ( ++currentId ) + '"' + evt.data.dataValue.substr( 2 );
}

}, null, null, 20 ); // Execute after autolink.

editor.on( 'afterPaste', function() {
@@ -117,6 +117,54 @@ bender.test( {
} );
},

// #13420.
'test link with encodable characters': function() {
var links = [
// Mind that links differ in a part g/200/3xx so it is easier and faster
// to check which link failed the test.

// Pasting a link alone:
// No encoding:
'https://foo.bar/g/200/301?foo="æåãĂĄ"',

// Partially encoded:
'https://foo.bar/g/200/302?foo=%22%20æåãĂĄ%22',

// Fully encoded:
'https://foo.bar/g/200/303?foo=%22%20%C3%A6%C3%A5%C3%A3%C4%82%C4%84%22',

// Encoded twice:
'https://foo.bar/g/200/304?foo=%2522%2520%25C3%25A6%25C3%25A5%25C3%25A3%25C4%2582%25C4%2584%2522',

// &amp; not encoded:
'https://foo.bar/g/200/305?foo="æåãĂĄ"&bar=bar',

// &amp; encoded:
'https://foo.bar/g/200/306?foo="æåãĂĄ"&amp;bar=bar',

// Pasting <a> element:
// &amp;:
'<a href="https://foo.bar/g/200/307?foo=%20æåãĂĄ%20&amp;bar=bar">https://foo.bar/g/200/307?foo=%20æåãĂĄ%20&amp;bar=bar</a>',

// Quote sign:
'<a href="https://foo.bar/g/200/310?foo=&quot;æåãĂĄ&quot;">https://foo.bar/g/200/310?foo=&quot;æåãĂĄ&quot;</a>',
'<a href="https://foo.bar/g/200/310?foo=%22æåãĂĄ%22">https://foo.bar/g/200/310?foo="æåãĂĄ"</a>',
'<a href="https://foo.bar/g/200/311?foo=%22æåãĂĄ%22">https://foo.bar/g/200/311?foo=%22æåãĂĄ%22</a>',

// Mixed encoding:
'<a href="https://foo.bar/g/200/312?foo=%22%20%C3%A6%C3%A5%C3%A3%C4%82%C4%84%22">https://foo.bar/g/200/312?foo=%22%20æåãĂĄ%22</a>'
];

var autoEmbedRegExp = /data-cke-autoembed="\d+"/;

for ( var i = links.length; i--; ) {
assertPasteEvent( this.editor, { dataValue: links[ i ] }, function( data ) {
// Use prepareInnerHtmlForComparison to make sure attributes are sorted.
assert.isMatching( autoEmbedRegExp, bender.tools.html.prepareInnerHtmlForComparison( data.dataValue ) );
} );
}
},

'test uppercase link is auto embedded': function() {
var pastedText = '<A href="https://foo.bar/bom">https://foo.bar/bom</A>',
expected = /^<a data-cke-autoembed="\d+" href="https:\/\/foo.bar\/bom">https:\/\/foo.bar\/bom<\/a>$/;

0 comments on commit 2b30328

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