Fix encoded characters in term labels in Instant Results #3113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
The data for taxonomy term aggregations is send to Elasticsearch as encoded JSON, like this:
'{\"term_id\":236,\"slug\":\"blue\",\"name\":\"Blue\",\"parent\":0,\"term_taxonomy_id\":236,\"term_order\":0}'
This causes some characters, such as ampersands, inside the
name
field to be encoded as HTML entities. This means that when terms are displayed as facet options in Instant Results these characters are displayed in their encoded form.This fix uses the (tiny) @wordpress/html-entities package to decode these entities.
Closes #3097
How to test the Change
Create a term that includes an
&
character and assign it to a post. Add the term's taxonomy as a facet to Instant Results and search for the post. The&
should appear as expected in the list of facet options, and not as&
. The character should also appear correct in the active filter 'chip' when the term is applied as a filter.Changelog Entry
Fixed - An issue where some characters in taxonomy terms would appear encoded when displayed in Instant Results.
Credits
Props @JakePT
Checklist: