Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
fix pasting invalid links
Browse files Browse the repository at this point in the history
Summary:
I got a bug report today where someone was trying to copy/paste some content and nothing happened at all. I discovered that this was due to a bad link in her content, something like this:

```
<a href="https:// https://www.facebook.com">Faceboook</a>
```

In Chrome, this passes all the checks in `isValidAnchor`, but throws an error later on this line inside `_addAnchorNode`:
```
entityConfig.url = new URI(anchor.href).toString();
```
To account for this, I added an explicit `URI.tryParseURI` inside `isValidAnchor`.

Reviewed By: claudiopro

Differential Revision: D22601322

fbshipit-source-id: 61cf050bb6e4a31bbe95995ad3f57e8f39a1d954
  • Loading branch information
Frank Thompson authored and facebook-github-bot committed Jul 21, 2020
1 parent fc9395f commit 862a5b2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/model/encoding/convertFromHTMLToContentBlocks.js
Expand Up @@ -161,8 +161,9 @@ const isValidAnchor = (node: Node) => {
return false;
}
const anchorNode: HTMLAnchorElement = (node: any);
return !!(
anchorNode.href &&
return (
!!anchorNode.href &&
URI.tryParseURI(anchorNode.href) != null &&
(anchorNode.protocol === 'http:' ||
anchorNode.protocol === 'https:' ||
anchorNode.protocol === 'mailto:' ||
Expand Down

0 comments on commit 862a5b2

Please sign in to comment.