alleyinteractive / alleyinteractive/rewrite-testing

False negatives when a site is using verbose page rules

Open
#4 3 comments 0 reactions 0 assignees View on GitHub
awaiting verification bug
Dominant language
PHP
Stars
44
Forks
4
PR merge metrics
No merged PRs in 30d

Description

If a site is using a permalink structure which begins with `%postname%`, `%category%`, `%tag%`, or `%author%`, it'll trigger verbose page rewrite rules ([source](https://github.com/WordPress/WordPress/blob/4.1.1/wp-includes/rewrite.php#L2089-L2093)).

Verbose page rewrite rules means that `WP::parse_request()` will use `get_page_by_path()` if a given rewrite rule is a `pagename` rule ([source](https://github.com/WordPress/WordPress/blob/4.1.1/wp-includes/class-wp.php#L204-L216)) to check that a matching page exists, rather than simply allowing the rewrite rule to match.

This means a `pagename` rule will not match if the page doesn't actually exist on the site, and it'll allow a subsequent rewrite rule to match. This is the only time where a matching rewrite rule can fall through and allow a subsequent rule to match.

Rewrite Rule Testing doesn't take this into account, therefore its behaviour doesn't match WordPress' behaviour when matching a rewrite rule to its query.

The net result is that you can have rewrite tests which Rewrite Rule Testing falsely match to a page rewrite rule, when it should be matching WordPress core's behaviour by checking the match with `get_page_by_path()` and falling back to a subsequent rule if it doesn't exist.

**tl;dr** Rewrite Rule Testing reports false negatives because its logic doesn't match core's.

Fix coming up shortly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.