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.
- register a public taxonomy with spaces in the name (e.g.,
register_taxonomy( 'this is a test', 'post' );
- add a term to that taxonomy and assign it to at least one post
- Load the sitemap index in your browser
- See something like
https://example.com/wp-sitemap-taxonomies-this%20is%20a%20test-1.xml
- 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,
- create and register a custom provider, whose
$object_type = 'this is a test';
- 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).
- Load the sitemap index in your browser
- See something like
https://example.com/wp-sitemap-this%20is%20a%20test-1.xml
- 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.