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
pasteHandler() incorrectly treats some strings as links #46287
Comments
I can replicate this issue WordPress 6.1.1 |
I think protocols are not limited to Also, the code you suggested determines that URLs with protocols such as However, since I think few users will paste URLs with irregular custom protocols, it might be a good idea to determine major protocols as correct URLs. |
I noticed that the same issue was discussed in #24895. And PR #28534 is the solution to this problem. Also, as noted in this comment, an approach using |
@t-hamano Thank you for finding the older issue PR, I had not been able to locate that in my own searching! I do believe that it's unusual for an href to have a space in it. Apple's documentation around This issue definitely describes the same problem as #24895. |
Description
When selecting some content and trying to paste other content into its place, certain strings are interpreted as links which should not be. This causes the selected text to be converted to an invalid link, instead of replacing the selected text with the clipboard contents.
This occurs because the check for whether a text
isURL
is to run it through the browser's URL constructor, and any non-error result is treated as proof the string is a URL. Passing a string formattedWord: Other Words
into this constructor results in a valid URL object, with not-really-URL contents. For example the stringMovie: The Revenge of Sequels II
in the example below gets parsed as such:movie:
is interpreted as a protocol, andThe Revenge of Sequels II
is treated as the pathname. (Note the leading space in that string.) This is valid on the part ofURL
, but the likelihood of a user consciously pasting a valid URL with a leading space in the path name seems excruciatingly low.I propose that we should also check the first character of the
pathname
on the generatedURL
object, and assume the content is not a URL if that character is whitespace:It's possible I am overlooking some category of URLs where a leading space in the pathname would still be valid, but this heuristic works with every link type I can think of.
Step-by-step reproduction instructions
Movie: The Revenge of Sequels II
to the clipboardMovie: The Revenge of Sequels II
) over the text "Replace me"Movie: The Revenge of Sequels II
Screenshots, screen recording, code snippet
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: