url() doesn't double base_path. url(),nor manage correctly url starting with "/"

Created on 19 February 2015, almost 10 years ago
Updated 10 October 2023, about 1 year ago

When you use a base_url setted in settings.php and this base_url contain a not empty base_path, the returned url from url() can have a doubled base_path like : http://host/base_path//base_path/.... Or /base_path//base_path/…

If you use, for instance, linkit in a link field, You can see this bug:

Case 1) If you use linkit to return a node path. Linkit return a path like "node/3" to the link field and url("node/3") return "http://host/base_path/node/3" => correct

Case 2) If you use linkit to return a file path. Linkit return a relative url like "/base_path/sites/mysite/files/…." to the link field and url("/base_path/sites/mysite/files/…") return "http://host/base_path//base_path/ sites/mysite/files/…" => wrong

But linkit works fine: "/base_path/sites/mysite/files/…." is a correct relative url. The mistake doesn't come from linkit or link modules but really from the url() function.

Conclusion:
When url() receives a path starting with a "/" it must be added only base_root or nothing (depending if it has been asked an absolute or relative url), and when it receives a path without "/" it must be added base_url or base_path (depending if it asked an absolute or relative url)

See patch below.

🐛 Bug report
Status

Needs work

Version

7.0 ⚰️

Component
Base 

Last updated 2 days ago

Created by

Live updates comments and jobs are added and updated live.
  • API change

    Changes an existing API or subsystem. Not backportable to earlier major versions, unless absolutely required to fix a critical bug.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024