-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
FIX(BB-564) : Converted revision notes string url to clickable links #572
Conversation
It is probably because of missing typescript types. Let me know if that fixes it. |
I installed this package but still getting the error. I tried debugging it using console.log
DOMPurify.sanitize is undefined |
Hm. In another project I imported it like this: |
Tried this but same results. Can you check it on this branch on your system. Or what about using sanitize-html package alternative to dompurify. |
I ran
Everything works as expected, no warnings of any kind. |
hm, our current regex needs to be modified 👀
Yes indeed, we should also convert URLs without the protocol at the beginning. |
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.
So I should probably have realized earlier, but we're going to want to make this code more reusable by extracting it into a utility function (probably in src/client/helpers/utils.ts).
For example on any page with revision notes (e.g. revision page: https://test.bookbrainz.org/revision/29833), as well as annotations (https://github.com/bookbrainz/bookbrainz-site/blob/master/src/client/components/pages/entities/annotation.js#L49).
In the future there will be more uses for it but let's start with those.
The utility should return the whole <span>
element with the dangerouslySetInnerHTML
.
Separately to that, something else we missed is that a short url (www.xyz…
) will be parsed correctly, but the url is interpreted relative to the current page.
Here's an example where on the page http://localhost:9099/editor/1245/revisions
, the url www.bookbrainz.org
will link to http://localhost:9099/editor/1245/revisions/www.bookbrainz.org
:
If I manually turn the URL from www.bookbrainz.org
to https://www.bookbrainz.org
(or even the less descriptive //www.bookbrainz.org
), it points to the right page.
Full URLs are working fine however 👍
Then I guess we will need to rename our utils.ts file to utils.tsx so that we can return jsx @MonkeyDo what are your thoughts on this ? |
Yes, that's fine. There are no ill effects with doing that. |
Added |
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.
Looking good !
Last bits before merging this useful tool.
Otherwise the tests break. See cure53/DOMPurify#29
Problem
This PR Fixes: BB-564
Solution
Used
regex
to convert any string url that has a prefixhttp|https|ftp|ftps
to a clickablelink
and then rendered the HTML string as real HTML.Before
bandicam.2021-03-14.20-11-46-501.mp4
After
bandicam.2021-03-14.20-11-12-974.mp4