-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Editor crashes after inserting a specific HTML embed #8323
Comments
Example HTML: <h2>CKEditor 5 on socials</h2><div class=\"raw-html-embed\"><blockquote class=\"twitter-tweet\"><p dir=\"ltr\" lang=\"en\">Keeping CKEditor 5 integrations tidy and free of bugs 🐛 The new release for the official <a href=\"https://twitter.com/hashtag/Angular?src=hash&ref_src=twsrc%5Etfw\">#Angular</a> WYSIWYG editor component works with Angular 9.1 and above. <a href=\"https://t.co/Umag7F9dq0\">https://t.co/Umag7F9dq0</a> <a href=\"https://t.co/cIPy5fFSDn\">pic.twitter.com/cIPy5fFSDn</a></p>— CKEditor Ecosystem (@ckeditor) <a href=\"https://twitter.com/ckeditor/status/1318575258153160707?ref_src=twsrc%5Etfw\">October 20, 2020</a></blockquote><script charset=\"utf-8\" src=\"https://platform.twitter.com/widgets.js\" async=\"\"></script></div><div class=\"raw-html-embed\"><iframe allowfullscreen=\"\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" frameborder=\"0\" src=\"https://www.youtube-nocookie.com/embed/DgM5DfAPQTI\" height=\"315\" width=\"560\"></iframe></div><p>Psst, we're tracking ya!</p><div class=\"raw-html-embed\"><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview'); </script></div> |
It fails when we try to get raw HTML from the view element. ckeditor5/packages/ckeditor5-html-embed/src/htmlembedediting.js Lines 106 to 109 in 64c87e5
The HTML used to test is invalid. Our tools don't parse it correctly: Everything works fine with clean structure: <h2>CKEditor 5 on socials</h2>
<div class="raw-html-embed">
<blockquote class="twitter-tweet"><p dir="ltr" lang="en">Keeping CKEditor 5 integrations tidy and free of bugs 🐛 The new release
for the official <a href="https://twitter.com/hashtag/Angular?src=hash&ref_src=twsrc%5Etfw">#Angular</a> WYSIWYG editor
component works with Angular 9.1 and above. <a href="https://t.co/Umag7F9dq0">https://t.co/Umag7F9dq0</a> <a
href="https://t.co/cIPy5fFSDn">pic.twitter.com/cIPy5fFSDn</a></p>— CKEditor Ecosystem (@ckeditor) <a
href="https://twitter.com/ckeditor/status/1318575258153160707?ref_src=twsrc%5Etfw">October 20, 2020</a></blockquote>
<script charset="utf-8" src="https://platform.twitter.com/widgets.js" async=""></script>
</div>
<div class="raw-html-embed">
<iframe allowfullscreen="" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" frameborder="0" src="https://www.youtube-nocookie.com/embed/DgM5DfAPQTI" height="315" width="560"></iframe></div><p>Psst,
we're tracking ya!</p>
<div class="raw-html-embed">
<script>( function ( i, s, o, g, r, a, m ) {
i[ 'GoogleAnalyticsObject' ] = r;
i[ r ] = i[ r ] || function () {
( i[ r ].q = i[ r ].q || [] ).push( arguments )
}, i[ r ].l = 1 * new Date();
a = s.createElement( o ), m = s.getElementsByTagName( o )[ 0 ];
a.async = 1;
a.src = g;
m.parentNode.insertBefore( a, m )
} )( window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga' );
ga( 'create', 'UA-XXXXX-Y', 'auto' );
ga( 'send', 'pageview' ); </script>
</div> I'm wondering whether we should try to render invalid structures. Couldn't we display a container with an error message if something went wrong during parsing the input HTML? |
Yeah, our parser and HTML->View->HTML processing is a bit limited, so it's actually a good idea. Also, which is a bigger problem, I've just realized that ideally, we should take the DOM structure directly from HtmlDataProcessor and avoid processing it to a view structure as it's going to:
I think it could be doable to have an instance of the DOM converter in upcast converters. It'd require some changes in This might also help with tricky cases like what MathType guys do. Moreover, with some more work, it could lead to a nice optimization – we could configure the cc @jodator |
The In branch https://github.com/ckeditor/ckeditor5/compare/i/8323 I prepared a WIP of the approach, where we are able to register some elements that should be treated by the |
The idea behind it is nice IMO. It is easy to extend AFAICS. As the POC looks OK, I'd expose this API on For the solution:
|
I like the idea very much 👍
I'm also unsure whether using the cdata concept will convey the message to developers.
My other worry is – where can we expose this API? If on the data processor, then only on XML/HTML ones? Or on the MD data processor too? How will a feature know whether it can use this API? By duck typing? Or will this be an abstract method of the base data processor class? Or should we move this API elsewhere? My next worry is – what about performance? If every node that's being converted from DOM to View is being checked with our Matcher it may have a significant impact on performance, even if this matcher has no rules. Could you check it? Can we secure us from this? Or maybe we should not use Matcher but a simple callback check?
👍 cc @xaviripo |
I think that every processor should implement it. For example code blocks in markdown could be processed in this way (this could reduce code in some other places).
I'll check that, but by looking at the |
What do you need from our side? |
I checked the performance in |
Nothing :) Just wanted to let you know that we'll work on such a PoC. Perhaps you'll be able to update your implementation accordingly. |
Oh, my bad. Yeah, this looks promising. It's been a while since I've taken a look at our plugin's code but IIRC we had some possible improvements that depend on this issue. If Wiris can help somehow, just let me know. |
Feature (engine): Introduce the `DataProcessor#registerRawContentMatcher()` API that marks content sections that contains arbitrary character data and should not be parsed during conversion. See #8323. Fix (html-embed): Editor will not crash after inserting a broken HTML. Closes #8323. Fix (engine): `DomConverter` will not trim whitespaces in nodes that are siblings to inline raw content elements (e.g. MathML). Closes #5870.
📝 Provide detailed reproduction steps (if any)
editor.getData()
and copy the string.htmlEmbed.showPreviews
tofalse
.❌ Actual result
The editor crashes permanently.
Error from Chrome:
Error from Safari:
📃 Other details
I was able to reproduce it only in docs, the manual test works fine for me.
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: