wintercms / wintercms/winter

Translate parameters - urlFromPattern bug

Open
#1,104 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.5k
Forks
246
Avg merge
19h 2m
Merged PRs (30d)
7

Description

Winter CMS Build

dev-develop

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

I think we have wrong behaviour in winter/storm/src/Router/Helper.php getParameterName function.
In old october cms version (1.x) this function looked like this -
image

but now it is like this -

image

and if we have url pattern like this -

url = "/some/:dest|^destinations$|^world$|^countries$/:region?*"

when we run $this->getRouter()->getParameters(); for url "some/destinations/central-america/belize/"
we get such array -

array:2 [
"dest" => "destinations"
"region?" => "central-america/belize"
]

but then in function urlFromPattern in Router.php we have following situation -

here

image

for parameter "region?", function Helper::getParameterName returns "region", instead of "region?" like it was in previous version (see above) , this is due to this condition -

image

and then, in this condition -
$parameterExists = array_key_exists($paramName, $parameters) &&

we have false, because "region" key does not exist in params array, and we have wrong url like -
"some/destinations"

instead of

"some/destinations/central-america/belize"

In order to solve this, I had to remove "?" from params keys, before passing it to urlFromPattern($pattern, $parameters = [])

Steps to replicate

see above

Workaround

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in winter/storm/src/Router/Helper.php at getParameterName and Router.php at urlFromPattern. Reproduce the supplied pattern and URL with getRouter()->getParameters(), then verify that rebuilding the URL preserves the region? value and produces the expected full path instead of dropping it.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.