benjaminkott / benjaminkott/bootstrap_package

url()-function in ScssParser doesn´t resolve urls to public resources in composer-mode

Open
#1,445 12 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
355
Forks
212
Avg merge
1h 4m
Merged PRs (30d)
31

Description

Hello,

this is my first Bug-Report.

# Bug Report

## Prerequisites

* [x] Can you reproduce the problem on TYPO3 v12.4 LTS
* [x] Did you [perform a cursory search](https://github.com/issues?q=is%3Aissue+user%3Abenjaminkott+repo%3Abenjaminkott%2Fbootstrap_package)
to see if your bug or enhancement is already reported?

## Description

The url-parser inside the ScssParser doesn´t resolve the paths to public resources correct in a composer-environment. Instead of resolving the "Resources/Public"-path of an extension to "_asset/id", it delivers the server-path.

## Steps to Reproduce

I build my own theme.scss in my sitepackage and want to link to resources inside the public-folder:
`background-image: url('../../../Public/Icons/test.svg');`

As a result in the parsed css, i get:
`background-image: url("../../../../var/www/html/vendor/q4u/sitepackage/Resources/Public/Icons/test.svg");`

In composer-mode the public resources are linked in the _asset-folder, so i expect something like this:
`background-image: url("../../../../_assets/1aed38cddafbbebcfacb851cbb5e0b11/Icons/test.svg");`

This behavoir can also be reproduced with absolute paths.

### Expected behavior

Resolving the resources to the _assets-Folder for composer-installations.

### Actual behavior

The resources are resolved to an absolute server path prefixed with some "../"

### Possible solution

I debugged a bit. Maybe this could work (just tested with relative paths in composer-mode):

Inside Classes/Parser/ScssParser.php:
Instead of:
```
if (substr_compare($result, 'data:', 0, 5, true) !== 0) {
if (is_file(PathUtility::getCanonicalPath($absoluteFilePath . '/' . $result))) {
$result = PathUtility::getCanonicalPath($relativeFilePath . '/' . $result);
} elseif (is_file(PathUtility::getCanonicalPath($absoluteBootstrapPackageThemePath . '/' . $result))) {
$result = PathUtility::getCanonicalPath($relativeBootstrapPackageThemePath . '/' . $result);
}
$result = substr($result, 0, 1) === '/' ? substr($result, 1) : $result;
}
```
surround the results with `PathUtility::getAbsoluteWebPath()` like this:
```
if (substr_compare($result, 'data:', 0, 5, true) !== 0) {
if (is_file(PathUtility::getCanonicalPath($absoluteFilePath . '/' . $result))) {
$result = PathUtility::getAbsoluteWebPath(PathUtility::getCanonicalPath($relativeFilePath . '/' . $result));
} elseif (is_file(PathUtility::getCanonicalPath($absoluteBootstrapPackageThemePath . '/' . $result))) {
$result = PathUtility::getAbsoluteWebPath(PathUtility::getCanonicalPath($relativeBootstrapPackageThemePath . '/' . $result));
}
$result = substr($result, 0, 1) === '/' ? substr($result, 1) : $result;
}
```
## Versions

TYPO3: 12.4.8
bootstrap_package: 14.0.7

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in Classes/Parser/ScssParser.php and inspect how relative and absolute url() paths are resolved in composer mode. Reproduce the example with a resource under Resources/Public and compare the generated CSS. Done means those URLs resolve to the public _assets path rather than an absolute server path, including the reported absolute-path case.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, scss
Domain
backend, build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.