Skip to content

[11.x] check not empty before concat url #55810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 11.x
Choose a base branch
from

Conversation

MrTuffaha
Copy link

When using packages that adds a default prefix in filesystem config (example steffjenl/laravel-azure-blob-storage).

The FilesystemAdapter adds a "/" before the path as it only checks if prefix is set not also if its not empty, this may result in a url with double slashes "//".

this pull checks if prefix is not empty before combining it with path

@MrTuffaha MrTuffaha changed the title if prefix is set as empty string dont add start forward slash [11.x] check prefix not empty before concat with path May 21, 2025
@MrTuffaha MrTuffaha changed the title [11.x] check prefix not empty before concat with path [11.x] check not empty before concat url May 21, 2025
@rodrigopedra
Copy link
Contributor

Likely a breaking change:

<?php

function originalImplementation($url, $path)
{
    return rtrim($url, '/') . '/' . ltrim($path, '/');
}

function proposedImplementation($url, $path)
{
    if (empty($url)) {
        return trim($path, '/');
    }

    if (empty($path)) {
        return trim($url, '/');
    }

    return rtrim($url, '/') . '/' . ltrim($path, '/');
}

$urls = ['', 'https://url.with.slash/', 'https://url.without.slash'];
$paths = ['', '/', 'path', 'path/', '/path', '/path/'];

foreach ($urls as $url) {
    foreach ($paths as $path) {
        echo originalImplementation($url, $path), PHP_EOL;
    }

}

echo str_repeat('-', 80), PHP_EOL;

foreach ($urls as $url) {
    foreach ($paths as $path) {
        echo proposedImplementation($url, $path), PHP_EOL;
    }
}

Output:

$ php test.php 
/
/
/path
/path/
/path
/path/
https://url.with.slash/
https://url.with.slash/
https://url.with.slash/path
https://url.with.slash/path/
https://url.with.slash/path
https://url.with.slash/path/
https://url.without.slash/
https://url.without.slash/
https://url.without.slash/path
https://url.without.slash/path/
https://url.without.slash/path
https://url.without.slash/path/
--------------------------------------------------------------------------------


path
path
path
path
https://url.with.slash
https://url.with.slash/
https://url.with.slash/path
https://url.with.slash/path/
https://url.with.slash/path
https://url.with.slash/path/
https://url.without.slash
https://url.without.slash/
https://url.without.slash/path
https://url.without.slash/path/
https://url.without.slash/path
https://url.without.slash/path/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants