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

fix: querying posts by slug or uri when the post name is non-ascii #2851

Merged

Conversation

jasonbahl
Copy link
Collaborator

@jasonbahl jasonbahl commented Jul 11, 2023

What does this implement/fix? Explain your changes.

This fixes a bug where querying posts by slug or uri was returning null when the post's name (slug) included non-ascii characters.

Failing Tests: https://github.com/wp-graphql/wp-graphql/actions/runs/5521919716/jobs/10070736088?pr=2851
Passing Tests: https://github.com/wp-graphql/wp-graphql/actions/runs/5522008949/jobs/10070950056?pr=2851

Does this close any currently open issues?

Any other comments?

I've created 2 posts with the following titles:

  • (Persian) سلام-دنیا
  • (Emoji) 🍌

CleanShot 2023-07-11 at 09 18 01

This gives me posts visible at the following URLs:

  • /blog/2023/07/11/🍌/
  • /blog/2023/07/10/سلام-دنیا/

Before:

Querying these posts by their slugs / uri would return null:

CleanShot 2023-07-11 at 09 27 43

After:

Querying these posts by their slugs / uri returns the expected nodes:

CleanShot 2023-07-11 at 09 28 35

@@ -527,7 +527,7 @@ protected function init() {
return ! empty( $this->data->ping_status ) ? $this->data->ping_status : null;
},
'slug' => function () {
return ! empty( $this->data->post_name ) ? $this->data->post_name : null;
return ! empty( $this->data->post_name ) ? urldecode( $this->data->post_name ) : null;
Copy link

Choose a reason for hiding this comment

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

Avoid too many return statements within this method.

@@ -683,7 +683,7 @@ protected function init() {
$link = get_permalink( $this->data->ID );
}

return ! empty( $link ) ? $link : null;
return ! empty( $link ) ? urldecode( $link ) : null;
Copy link

Choose a reason for hiding this comment

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

Avoid too many return statements within this method.

@codeclimate
Copy link

codeclimate bot commented Jul 11, 2023

Code Climate has analyzed commit fa8d9cb and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

@coveralls
Copy link

Coverage Status

coverage: 85.064%. remained the same when pulling fa8d9cb on jasonbahl:fix/#2847-not-resolving-unicode-slugs into f711cc1 on wp-graphql:develop.

@jasonbahl jasonbahl merged commit 85852e2 into wp-graphql:develop Jul 12, 2023
33 of 34 checks passed
@jasonbahl jasonbahl mentioned this pull request Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants