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

URL sanitization ClickableLinkPlugin #5302

Merged
merged 1 commit into from
Nov 29, 2023
Merged

Conversation

yeion7
Copy link
Contributor

@yeion7 yeion7 commented Nov 28, 2023

Even though URLs undergo sanitization when the Link Node generates the DOM, when someone clicks a link using the ClickableLinkPlugin, the link isn't sanitized.

This pull request resolves the issue by sanitizing the URL within the event handler.

Copy link

vercel bot commented Nov 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2023 4:14pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2023 4:14pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2023
@@ -61,7 +61,7 @@ export default function LexicalClickableLinkPlugin({
$isElementNode,
);
if ($isLinkNode(maybeLinkNode)) {
url = maybeLinkNode.getURL();
url = maybeLinkNode.sanitizeUrl(maybeLinkNode.getURL());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking about whether it might be better to have sanitizeUrl within getURL so that getUrl always hands back a cleaned-up URL.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's probably a reason why I separated these things, but I can't remember exactly what it is. Maybe so you could override them separately?

How is this implemented elsewhere in the codebase? Let's just be consistent for now, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After digging into the codebase, I found that it sanitizes right after grabbing the URL, so I think we're good with the current approach.

@acywatson acywatson merged commit 2730895 into facebook:main Nov 29, 2023
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants