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

Error when pasting HTML containing /data-slate-fragment="(.+?)"/ in text #5328

Open
12joan opened this issue Mar 2, 2023 · 0 comments
Open

Comments

@12joan
Copy link
Contributor

12joan commented Mar 2, 2023

Description
The regular expression catchSlateFragment matches /data-slate-fragment="(.+?)"/ anywhere in pasted HTML, including in text nodes. This casues an error if the capture group isn't a properly formatted Slate fragment. The error doesn't crash the editor, but it does prevent pasting.

Recording
https://user-images.githubusercontent.com/4272090/222422917-00f36461-3fe2-47a0-8dc7-77ee2594652e.mp4

Sandbox
https://www.slatejs.org/examples/richtext

Steps
To reproduce the behavior:

  1. Open Rich Text example in Browser A and Browser B
  2. In Browser A, type data-slate-fragment="[any text here]"
  3. Copy all text
  4. Paste into Browser B
  5. Paste fails, error in console

In the case of Safari, pasting into the same editor also causes the error, since we cannot rely on application/x-slate-fragment (see #4998).

Expectation
We should ensure that data-slate-fragment is only parsed in the attributes of a HTML tag, not in text nodes. If fully parsing the HTML isn't an option, the following regular expression should suffice, so long as < tags are properly encoded in text nodes (which they should be).

/<[^>]+data-slate-fragment="(.+?)"/

Environment

  • Slate Version: 0.91.7
  • Operating System: macOS
  • Browser: Safari, (Chrome and Firefox when pasting between browsers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant