Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { Icon, chevronDown } from '@wordpress/icons';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';

/**
* Internal dependencies
Expand Down Expand Up @@ -50,7 +51,7 @@ export function LinkPreview( { title, url, image, badges } ) {
numberOfLines={ 1 }
className="link-preview-button__title"
>
{ title }
{ stripHTML( title ) }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The stripHTML removes HTML, but I don't think it decodes the entities.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think __unstableStripHTML (stripHTML) does decode the entities:

wp.dom.__unstableStripHTML( '<b>Hello &amp; World</b>' )
// => "Hello & World" 

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wanted to ask whether we need to do something like decodeEntities( stripHTML( title ) )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TIL. We usually use decodeEntities in the codebase. If it works then why change :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My prediction is that if unpredictable HTML might be included, stripHTML might be better than decodeEntities. For example, stripHTML is also used in the post title:

If we trust fetchLinkSuggestions then maybe no?

https://github.com/WordPress/gutenberg/blob/fix/link-picker-entity/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.ts#L150

Perhaps fetchLinkSuggestions is intended for search results 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps fetchLinkSuggestions is intended for search results

Well... there is that too! 😆 Sorry I was in a rabbit hole.

I think with decodeEntities is fine if we're unsure if we're getting entity-encoded values. I just tested and couldn't break it. Not that that means much!

</Truncate>
{ url && (
<Truncate
Expand Down
Loading