Skip to content
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

Decode some characters if used in taxonomy name so it's displayed correctly in Query Loop filters #50376

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

kmanijak
Copy link
Contributor

@kmanijak kmanijak commented May 5, 2023

What?

A couple of characters are not decoded properly and displayed encoded:

  • & -> &
  • > -> >
  • < -> &lt;

This PR solves this problem.

Why?

Users should see decoded values in the frontend.

How?

Values provided to FormTokenField are now decoded using decodeEntities. Decoding happens only in presentation layer.

Testing Instructions

  1. Create a new post category (Posts -> Categories) with a name that includes &, <, > e.g. Sports & Games > winter <
  2. Assign a post to this new category
  3. Create a new post
  4. Include Query Loop
  5. Add Categories filter (Filters -> + -> Taxonomies)
  6. Type "Sports"
  7. Expected: Sports & Games > winter < is displayed as a suggestion (Not Sports &amp; Games &gt; WINTER &lt;)
  8. Click on this category
  9. Expected: Sports & Games > winter < is displayed as a chosen option (Not Sports &amp; Games) and posts are filtered correctly

Screenshots or screencast

Before After
image image

Note: Using the < and > characters in the title in this order makes the content disappear. For example:

  • Sports & Games <winter> becomes Sports & Games but that's not in the scope of this PR.
@kmanijak kmanijak requested a review from ajitbohra as a code owner May 5, 2023 12:31
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 5, 2023
@github-actions
Copy link

github-actions bot commented May 5, 2023

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @kmanijak! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@skorasaurus skorasaurus added [Feature] Inspector Controls The interface showing block settings and the controls available for each block [Block] Query Loop Affects the Query Loop Block labels Jun 1, 2023
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

Confirming this PR fixes the issue. Thanks @kmanijak!

One little suggestion is that I think we could use the displayTransform prop of <FormTokenField />, this way we only need to pass replaceAmpInTermName as a prop to the component, instead of having to .map() the array of suggestions. What do you think @kmanijak?

@kmanijak kmanijak changed the title Decode ampersand if used in taxonomy name so it's displayed correctly in Query Loop filters Nov 29, 2023
@Aljullu Aljullu added the [Type] Bug An existing feature does not function as intended label Nov 30, 2023
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

This is working great, @kmanijak! Code looks good and it's testing as expected.

However, I would like if somebody else could take a second look before merging. @ajitbohra @ntsekouras @jsnajdr can any of you help with that? 🙂

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@ntsekouras ntsekouras merged commit 9473d62 into WordPress:trunk Nov 30, 2023
51 of 52 checks passed
@github-actions github-actions bot added this to the Gutenberg 17.3 milestone Nov 30, 2023
derekblank pushed a commit that referenced this pull request Dec 7, 2023
…rectly in Query Loop filters (#50376)

* Decode ampersand if used in taxonomy name so it's displayed correctly in Query Loop filters

* Use more generic decoding function and in the displayTransform props of FormTokenField
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block [Feature] Inspector Controls The interface showing block settings and the controls available for each block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
4 participants