-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Strip meta tags from pasted links in Chromium #36356
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
Conversation
|
@gVee Would you be able to verify this fixes the issue? |
|
Size Change: +36 B (0%) Total Size: 1.09 MB
ℹ️ View Unchanged
|
|
Also pinging @kevin940726 for review as he is the regex guru 😄 |
905c331 to
def7e39
Compare
kevin940726
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh, there could be some false positives here. Since this is only happening in chromium and mac, should we add some UA detection to opt-in to this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since that we have the exact source in chromium, I don't think we have to do regex search here. We can simply do:
const metaTag = "<meta charset='utf-8'>";
if (html.startsWith(metaTag)) {
return html.slice(metaTag.length);
}and maybe it's a little bit faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will that match on both single and double quotes around the Update: I checked and it does work 🥳 .charset attribute?
I'm sure I tried this as my first implementation and it didn't work but maybe I made a typo first time around.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I made a typo in the comment, I updated it.
Will that match on both single and double quotes around the charset attribute?
I don't think we have to worry about double quotes, no? Since we can clearly see that it's being hard-coded as single quotes in the source.
I don't think we need to do that. If the tag isn't there it won't be removed. The overhead is so minimal as to make the UA detection less valuable. |
b36ac88 to
62bb136
Compare
|
Moved discussion to #36392. @ellatrix I was looking at adding an integration test to cover this. Initially it seemed like we already have one but upon closer testing it doesn't assert on the same problem. According to the
...then all the filters in gutenberg/packages/block-editor/src/components/rich-text/use-paste-handler.js Lines 128 to 131 in 7a41d02
These filters are those within Therefore the integration test which exclusively uses It looks like we can't pass inline pasted content through If we don't do something it's going to be very difficult to assert on the handling of pasting rich inline content. For example, I tired adding an e2e tests to cover the Do you have any thoughts on the best way forward here? |
|
Going to merge this in order to fix the bug and we can circle back to integration tests and improving the actual implementation. |
* Strip meta tag * Corrections for accuracy * Simply by avoiding regex
|
sorry for late reply, and thanks @getdave @kevin940726 . It's working. Hope this back to WP soon. By the way, should it provide a way clearing script that dealing with superfluous meta tag in DB ? As mentioned like @isaumya here ? |
|
Hi @getdave & @kevin940726, Now after this patch though it won't be added again in the future contents but the old contents will still have the same artifacts present. So, naturally users needs to keep using functions like: add_filter( 'the_content', fn($content) => preg_replace('#</?meta(\s[^>]*)?>#i', '', $content) );in their I think the way WooCommerce has some asynchronous upgrader which runs when you upgrade to a major version, in this case Gutenberg should so something similar. What are your thoughts on this? |
|
I've raised this for the Open Floor of the next Core Editor meeting tomorrow https://make.wordpress.org/core/2021/11/22/editor-chat-agenda-24-november-2021/#comment-42139 |
Description
In #33585 we learnt that Chromium appends a meta tag to the start of pasted HTML. This means when you copy and paste a link (even one you created within Gutenberg) the underlying post's HTML contains a meta tag.
This PR fixes that by stripping out that meta tag but only if it's at the very beginning of the pasted string.
Edge case - this will of course mean that if someone is trying to paste a string with that exact meta tag then it will be impossible, but I'm not sure we can work around that one and it is very much an edge case.
How has this been tested?
Contrast that with
trunkwhere the bug is still manifesting itself.Fixes #33585
Screenshots
Screen.Capture.on.2021-11-09.at.17-59-18.mp4
Types of changes
Checklist:
*.native.jsfiles for terms that need renaming or removal).