processwire / processwire-issues

ProcessWire issue reports.
44 stars 2 forks source link

`$page->url()` produces incorrect URLs for some parameters #1915

Open michaellenaghan opened 5 months ago

michaellenaghan commented 5 months ago

Short description of the issue

$page->url() produces incorrect URLs for some parameters

Expected behavior

See the examples below, but basically: $page->url() should produce the same output as $input->url().

Actual behavior

In my home page template:

$input->url() produces correct URLs:

$page->url() does not:

Note that:

Optional: Suggestion for a possible fix

The issues are fairly straightforward.

For example, this line:

    'urlSegmentStr' => is_string($options) ? $options : '',

should be changed to something like this:

    'urlSegmentStr' => (is_string($options) && !in_array($options, array('+', '-'))) ? $options : '',

and this line:

    if($template->slashPageNum) $url .= '/';

should be changed to something like this:

    if($template->slashPageNum === 1) $url .= '/';

(When "Should page number URLs have a trailing slash?" is set to "No", $template->slashPageNum is set to -1, a truthy value.)

Steps to reproduce the issue

In a template:

  1. Check "Allow Page Numbers?"
  2. Set "Should page number URLs have a trailing slash?" to "No"
  3. Leave "Allow URL Segments?" unchecked

In the code for the template:

  1. Call $page->url('+')

Setup/Environment