8000 PathPackage not add BasePath if $versionedPath begun with / · Issue #46688 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
PathPackage not add BasePath if $versionedPath begun with / #46688
Closed
@gregsparrow

Description

@gregsparrow

Symfony version(s) affected

5.4

Description

\Symfony\Component\Asset\PathPackage::getUrl did not add basePath to $versionedPath if $versionedPath begin with /

It make sense if $versionedPath argument isAbsoluteUrl.
But if $versionedPath begin with / , this line of code return $this->getBasePath().ltrim($versionedPath, '/'); doesn't make any sense. If $versionedPath begin with / it never be trimmed of / from the left.

And in my case creating named asset package with base_path is meaningless. Cos it never used.

How to reproduce

file assets.yaml

framework:
    assets:
        packages:
            pdf:
                base_path: '%kernel.project_dir%/public/'
        json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'

file webpack.config.js configured by default

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build')
    // only needed for CDN's or sub-directory deploy
    //.setManifestKeyPrefix('build/')

file manifest.json contains lines that starts from /

"build/images/img.svg": "/build/images/img.svg",

some html.twig contains line like this

        <div class="flex-1">
            <img src="{{ asset('build/images/img.svg', packageName) }}" alt="img">
        </div>

So. I have asset with a named package - pdf. And during rendering of view, passing variable that holds the name of the package, to control the source from where file is loaded. I was hoping that base_path will be added. But it was not.

Possible Solution

remove ($versionedPath && '/' === $versionedPath[0]) and check only if ($this->isAbsoluteUrl($versionedPath))

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0