Bug #77722

absRefPrefix is not applied everywhere

Added by Robert Vock almost 3 years ago. Updated about 2 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Frontend
Start date:
2016-08-31
Due date:
% Done:

0%

TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

When I've set absRefPrefix, it is not set everywhere. One example is the srcset-attribute:

<img src="fileadmin/example.png" srcset="fileadmin/example.png 200w, fileadmin/example_400.png 400w">

gets converted to

<img src="/fileadmin/example.png" srcset="/fileadmin/example.png 200w, fileadmin/example_400.png 400w">

(only the first fileadmin in the srcset got replaced)

This happens because TypoScriptFrontendController::setAbsRefPrefix() just searches for "fileadmin as a simplification of finding attributes which start with a relative path.

One improvement would be to add the absRefPrefix in the getPublicUrl() method of ResourceStorage, if relativeToCurrentScript is false:
https://github.com/TYPO3/TYPO3.CMS/blob/84865ff97f567d412bf5b5cad4bc57aefaff3747/typo3/sysext/core/Classes/Resource/ResourceStorage.php#L1310

Then images which are used within srcset will already have the correct path. Of course this does not fix all missing prefixes, but at least all where FAL is used.


Related issues

Related to TYPO3 Core - Bug #72164: "absRefPrefix = auto" does not work if PageGenerator is not used Closed 2015-12-11
Related to TYPO3 Core - Bug #82486: IncludeJS* / includeCSS* (including compression / concatenation) ignoring absRefPrefix Closed 2017-09-14

History

#1 Updated by Benni Mack almost 3 years ago

I would suggest that the fix is, that it searches for all local storages and takes their prefixes and searches through them in the same place - what do you think?

#2 Updated by Robert Vock almost 3 years ago

The method TypoScriptFrontendController::setAbsRefPrefix() already loops over the storages and sets the absRefPrefix for all folders:
https://github.com/TYPO3/TYPO3.CMS/blob/2ba08444c9cd7613c97e10b65fd53867565f205c/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php#L3884

There it performs a simple str_replace, where it takes the prefix of each storage and prepends a quote. So it searches for "fileadmin instead of only fileadmin. This works in most cases, when the path directly appears in an attribute, but not when it appears at other places.

It's not possible to perform a simple str_replace, when you leave the quote, because you would also replace fileadmin where it already is prepended by a prefix or a domain. I think this would quickly introduce new bugs. That's why I would only change the getPublicUrl()-method of ResourceStorage. If the introduces coupling between ResourceStorage and TSFE is undesired, there could be a hook like emitPostGeneratePublicUrlSignal and TSFE fixes the paths within the hook.

#3 Updated by Ernesto Baschny almost 3 years ago

  • Status changed from New to Needs Feedback

Robert Vock, the original css_styled_content implementation of responsive images uses the cImage method, which calls ContentObjectRenderer::getImageSourceCollection which will take care of adding the absRefPrefix before each link before rendering. I am not sure how you ended up with the srcset without the absRefPrefix. Maybe you are not using the cImage API? Could you elaborate on that?

#4 Updated by Robert Vock almost 3 years ago

I am using Smarty as template engine, and work directly with FileReference-Objects within the template and call their getPublicUrl-method ;)

But either way, it's not restricted to srcset. Anywhere, where an integrator uses the publicUrl, and it is not at the start of an attribute, absRefPrefix will not work.

Another example is a background image:


lib.backgroundImage = IMG_RESOURCE
lib.backgroundImage.file.import.data = levelmedia:-1, slide
lib.backgroundImage.file.import.listNum = 0
lib.backgroundImage.file.treatIdAsReference = 1
lib.backgroundImage.stdWrap.wrap (
  <div style="background-image:url('|');" class="page-background"></div>
)

page.20 < lib.backgroundImage

Here the publicUrl is not prefixed with the absRefPrefix.

Other examples might be, if you want to output a url within JavaScript, which gets generated by TypoScript.

#5 Updated by Josef Glatz almost 3 years ago

I also discovered the problem in TYPO3 8.4.0-dev (master) within the `f:uri.resource` view helper. Is this intentionally, or even a relevant error?

#6 Updated by Christian Toffolo over 2 years ago

I also encountered this bug setting in a Fluid partial:

style="background-image: url('{f:cObject(typoscriptObjectPath: 'lib.imagePlaceholderFluid', data: {image: item.backgroundImage.0.uid})}');" 

The single quote after
url(
make function setAbsRefPrefix() to fail to add the absRefPrefix.

#7 Updated by Alexander Opitz over 2 years ago

  • Status changed from Needs Feedback to New
  • Target version set to Candidate for patchlevel
  • TYPO3 Version changed from 8 to 6.2

#8 Updated by David Bruchmann about 2 years ago

Depending on need the usage of absRefPrefix might be wrong here.
IMO there should be either a parameter if absRefPrefix shall be prepended or a second variable including the merged path.
As the usage is in different places perhaps the parameter solution is easier in realization and usage.
So a general approach to change the paths without options is wrong in my opinion.

#9 Updated by DANIEL Rémy over 1 year ago

  • Related to Bug #82486: IncludeJS* / includeCSS* (including compression / concatenation) ignoring absRefPrefix added

#10 Updated by Riccardo De Contardi over 1 year ago

  • Related to Bug #83630: Config.absRefPrefix not working anymore for includeCSS, includeJs, includeJSLibs, includeCSSLibs after update to 8.7.9 added

#11 Updated by Oliver Hader over 1 year ago

  • Related to deleted (Bug #83630: Config.absRefPrefix not working anymore for includeCSS, includeJs, includeJSLibs, includeCSSLibs after update to 8.7.9)

Also available in: Atom PDF