Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with double escaped autolink special characters #4910

Merged
merged 5 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ New Features:
* [#4807](https://github.com/ckeditor/ckeditor4/issues/4807): [Chrome] Improve the performance of pasting large images. Thanks to [FlowIT-JIT](https://github.com/FlowIT-JIT)!
* [#4850](https://github.com/ckeditor/ckeditor4/issues/4850): Added support for loading [content templates](https://ckeditor.com/cke4/addon/templates) from HTML files. Thanks to [Fynn96](https://github.com/Fynn96)!
* [#4874](https://github.com/ckeditor/ckeditor4/issues/4874): Added the [`config.clipboard_handleImages`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-clipboard_handleImages) configuration option for enabling and disabling built-in support for pasting and dropping images in the [Clipboard](https://ckeditor.com/cke4/addon/clipboard) plugin. Thanks to [FlowIT-JIT](https://github.com/FlowIT-JIT)!
* [#4858](https://github.com/ckeditor/ckeditor4/issues/4858): Fixed: [Autolink](https://ckeditor.com/cke4/addon/autolink) plugin incorrectly escapes `&` characters when pasting links into the editor.

Fixed Issues:

Expand Down
4 changes: 4 additions & 0 deletions plugins/autolink/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
}

function getHtmlToInsert( text ) {
// URL will be encoded later on with link.setAttribute method. Avoid
// double encoding of special characters (#4858).
text = CKEDITOR.tools.htmlDecodeAttr( text );

var link = new CKEDITOR.dom.element( 'a' ),
value = text.replace( /"/g, '%22' );

Expand Down
14 changes: 14 additions & 0 deletions tests/plugins/autolink/autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@
assertPasteEvent( this.editors.classic, { dataValue: pastedText }, { dataValue: pastedText, type: 'html' } );
},

// (#4858)
'test URL link with encoded characters': function() {
var pastedText = 'https://www.google.com/test/?one=one&two=two&three',
Comandeer marked this conversation as resolved.
Show resolved Hide resolved
expected = '<a href="https://www.google.com/test/?one=one&amp;two=two&amp;three">https://www.google.com/test/?one=one&amp;two=two&amp;three</a>',
spy = sinon.spy( CKEDITOR.tools, 'htmlDecodeAttr' );

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

spy.restore();

// Ensure that the test is correct.
assert.isTrue( spy.calledWithExactly( pastedText ), 'htmlDecodeAttr was called with incorrect input' );
},

'test mail link with text after': function() {
var pastedText = 'mail@example.com nope';

Expand Down
17 changes: 17 additions & 0 deletions tests/plugins/autolink/manual/encoding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h3>URLs that should be turned into links</h3>

<style>
input[type=text] { width: 450px }
</style>

<input type="text" readonly="readonly" value="https://www.google.com/test/?one=one&two=two&three">

<textarea id="editor" cols="10" rows="10">
<p>Foo bar.</p>
</textarea>

<script>
bender.tools.ignoreUnsupportedEnvironment( 'autolink' );

CKEDITOR.replace( 'editor' );
</script>
17 changes: 17 additions & 0 deletions tests/plugins/autolink/manual/encoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@bender-ui: collapsed
@bender-tags: 4.17.0, bug, 4858
@bender-ckeditor-plugins: clipboard, toolbar, wysiwygarea, elementspath, autolink, sourcearea, htmlwriter

Paste the given URL to the editor and check whether it's turned into a link. Make sure to also confirm links in source area.

## Expected

**Editor:** Link is pasted as it is, without additional encoding.

**Source area:** `&` characters are single encoded with `&amp;`.

## Unexpected

**Editor:** Special `&` characters are additionaly encoded to `&amp;`.

**Source area:** `&` characters are double encoded to `&amp;amp;`.