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

Conversation

jacekbogdanski
Copy link
Member

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#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.

What changes did you make?

Links were double escaped by executing 2x setAttribute method with already escaped & character to &.

Which issues does your PR resolve?

Closes #4858

@Comandeer Comandeer self-assigned this Sep 27, 2021
@Comandeer Comandeer self-requested a review September 27, 2021 10:07
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, however there is one edge case that fails after the changes:

https://www.google.com/test/?one=one&=1

If link contains intentional & sequence, it's converted to & instead of &. The same happens with < and other entities mentioned in allEscRegex in tools.js file.

tests/plugins/autolink/manual/encoding.md Outdated Show resolved Hide resolved
tests/plugins/autolink/manual/encoding.md Outdated Show resolved Hide resolved
@jacekbogdanski
Copy link
Member Author

The problem with the issue you mentioned is that there is no way (at the moment) to differentiate both escaped and unescaped characters when manipulating HTML in autolink plugin. Feeding autolink plugin with:

  • https://www.google.com/test/?one=1&two=2
  • https://www.google.com/test/?one=1&two=2
    will always result in passing escaped HTML to
    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' );
    value = value.match( CKEDITOR.config.autolink_urlRegex ) ? value : 'mailto:' + value;
    link.setText( text );
    link.setAttribute( 'href', value );
    // (#1824)
    var linkData = CKEDITOR.plugins.link.parseLinkAttributes( editor, link ),
    attributes = CKEDITOR.plugins.link.getLinkAttributes( editor, linkData );
    if ( !CKEDITOR.tools.isEmpty( attributes.set ) ) {
    link.setAttributes( attributes.set );
    }
    if ( attributes.removed.length ) {
    link.removeAttributes( attributes.removed );
    }
    link.removeAttribute( 'data-cke-saved-href' );
    return link.getOuterHtml();
    }

Both clipboard and typing operate on already processed HTML by a browser using copybin or text matcher.

This issue also exists in the older 4.15.1 version before #4858 regression, so I propose to extract it as a separate ticket as it looks like something more complicated to fix but also very unlikely to happen.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I've got just some doubts about unit test (see my inline comment).

tests/plugins/autolink/autolink.js Show resolved Hide resolved
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pasting a link with & will is changed to & which can breaks link
2 participants