Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

Provider $object_type and $sub_type need to be sanitized for the rewrite rules to match in some cases #166

@pbiron

Description

@pbiron

Describe the bug

The regexes used for the rewrite rules (both currently as in #150) would not match in certain cases without the $object_type and $sub_type properties of Core_Sitemaps_Provider being sanitized (most likely via santize_title() like the REST API does for it's routes).

To Reproduce
Steps to reproduce the behavior:

I came across these cases while testing #150...I tried them just to see what would happen :-) Since the buggy behavior they represent wasn't really in scope for #150 I figured it would be better to open a separate issue than include something about this in my review of that PR.

  1. register a public taxonomy with spaces in the name (e.g., register_taxonomy( 'this is a test', 'post' );
  2. add a term to that taxonomy and assign it to at least one post
  3. Load the sitemap index in your browser
  4. See something like https://example.com/wp-sitemap-taxonomies-this%20is%20a%20test-1.xml
  5. Click on that link and see that you get a 404 (because the rewrite rule wasn't matched...since it's regex doesn't allow a space)

Similarly,

  1. create and register a custom provider, whose $object_type = 'this is a test';
  2. add the other necessary methods to the custom provider so that it both shows up in the index (e.g., return >= 1 from max_num_pages()) and get_url_list() returns an array with at least 1 loc).
  3. Load the sitemap index in your browser
  4. See something like https://example.com/wp-sitemap-this%20is%20a%20test-1.xml
  5. Click on that link and see that you get a 404 (because the rewrite rule wasn't matched...since it's regex doesn't allow a space)

Expected behavior

I'd expect to see:

https://example.com/wp-sitemap-taxonomies-this-is-a-test-1.xml

and

https://example.com/wp-sitemap-this-is-a-test-1.xml

in both step 4's above and that clicking on those links correctly shows the relevant sitemaps

Additional context

I know the examples above are kind of pathological, but more real world cases are certainly possible.

Also, note that similar case for CPTs is handled correctly (e.g., register_post_type( 'this is atest', array( 'public' => true ) ) because register_post_type() sanitizes the post type (with sanitize_key().) So, register_taxonomy() should do the same? Although even in that case, custom provider $object_type should still be sanitized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions