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

[Product Collection] Fix: HTML Entity Decoding in Taxonomy Controls #11982

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Changes from 1 commit
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 @@ -6,6 +6,7 @@ import { Taxonomy } from '@wordpress/core-data/src/entity-types';
import { useState, useMemo, useRef } from '@wordpress/element';
import { useDebounce } from '@wordpress/compose';
import { FormTokenField } from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';

type Term = {
id: number;
Expand Down Expand Up @@ -250,6 +251,10 @@ const TaxonomyItem = ( { taxonomy, termIds, onChange }: TaxonomyItemProps ) => {
onChange( newTermIds );
};

const decodeHTMLEntities = ( value: string ) => {
return decodeEntities( value ) || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the need for the wrapping function and || '' part? Seems like decodeEntities always returns a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you can see in this code, it may return non-string value. Therefore, Just to be extra careful, I added || '' part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I implemented same thing for hand-picked products here, it resulted in an error. That’s why I added extra check here.

};

return (
<div className="wc-block-editor-product-collection-inspector__taxonomy-control">
<FormTokenField
Expand All @@ -261,6 +266,7 @@ const TaxonomyItem = ( { taxonomy, termIds, onChange }: TaxonomyItemProps ) => {
disabled={ isResolvingTermMaps }
// @ts-expect-error Using experimental features
__experimentalShowHowTo={ false }
displayTransform={ decodeHTMLEntities }
/>
</div>
);
Expand Down
Loading