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

Encode the ampersand character when pasting link address #15231

Merged
merged 4 commits into from
Oct 25, 2023

Conversation

mmotyczynska
Copy link
Contributor

Suggested merge commit message (convention)

Fix (clipboard): Pasting a link address should not convert its parts that look like HTML entities. Closes #15036.


Additional information

To reproduce the issue:

  1. Create (or use the below one) HTML link that contains HTML entity (like &times, &para, &quot etc.) in its href, e.g. https://example.com?x=1&quot=2&timestamp=t
  2. Right-click the link and choose the Copy Link Address option.
  3. Paste into the editor.

Without this fix, the parts &quot and &times are replaced with corresponding characters.

@@ -18,6 +18,8 @@ export default function plainTextToHtml( text: string ): string {
// Encode <>.
.replace( /</g, '&lt;' )
.replace( />/g, '&gt;' )
// Encode &.
.replace( /&/g, '&amp;' )
Copy link
Contributor

Choose a reason for hiding this comment

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

This is most probably to late, it would encode previously encoded &lt; and &gt;.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I already pushed a commit with the proper order of encoding.

Copy link
Contributor

@niegowski niegowski left a comment

Choose a reason for hiding this comment

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

Maybe a single integration test would be good to be added.

@niegowski niegowski merged commit 89eb065 into master Oct 25, 2023
@niegowski niegowski deleted the ck/15036-unexpected-html-escape-characters branch October 25, 2023 12:17
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.

Unexpected HTML escape character translation errors during pasting and source code switching
2 participants