[TYPO3-english] perfectlightbox/DAM: image link with spaces is not encoded and split apart to typolink options

Daniel Neugebauer mailinglists at energiequant.de
Wed Jun 20 13:00:37 CEST 2012


Hi!

We fell into some bug around perfectlightbox, DAM or Core (possibly): If 
you have an image that has spaces in its URL (typolink.parameter) and 
check "Enlarge on Click", they are not encoded and parts of the URL are 
split apart and used as typolink options (target attribute, CSS classes, 
...).

Example:

Image URL: fileadmin/some where/image.jpg
becomes:   <a href="fileadmin/some" target="where/image.jpg" ...

A workaround is to add a postUserFunc to the relevant typolink.parameter 
definitions of tt_content.image:

tt_content.image.20.1.imageLinkWrap.typolink.parameter
tt_content.image.20.1.imageLinkWrap.typolink.parameter.override


The following places are (in some way) relevant for that bug:

typo3conf/ext/perfectlightbox/static/setup.txt
   contains overrides for tt_content ... typolink

typo3/sysext/cms/tslib/class.tslib_content.php
   function typoLink, contains the line:
   $link_paramA = t3lib_div::unQuoteFilenames($link_param, TRUE);

t3lib/class.t3lib_div.php
   function unQuoteFilenames, performs the split on spaces

Of course, typoLink and unQuoteFilenames are a bit too late to fix 
anything. I couldn't locate the source of the unescaped 
typolink.parameter in time, but I suspect it may come from DAM or Core.


I couldn't find a bug report nor a previous mailinglist post about this. 
The bug is present with Typo3 4.5.16, Perfect Lightbox 3.1.4 and DAM 
1.2.4. Does anybody know of this issue yet? We don't have time to look 
further into this issue right now, but maybe someone more familiar with 
these modules already has an idea where to look next.

I'm appending our workaround; I hope it arrives without any wrapped lines.

Regards,
Daniel


Our workaround:

## WORKAROUND PERFECTLIGHTBOX [BEGIN]
# workaround for some bug in Typo3 Core/DAM/Perfectlightbox (couldn't 
locate...)
# problem:       perfectlightbox links to original image (as is done 
without perfectlightbox
#                so the bug could be located in DAM or core).
#                If that image URL uses spaces that are not encoded to 
%20, the link is mangled.
# reason:        The URL will be split up by typolink handling funtion 
via a call to t3lib's unQuoteFilenames
#                which splits typolink.parameter on spaces (target and 
other options). Since parameter has not
#                been URL encoded, we get parts of the URL in other 
a-tag parameters and a broken URL...
# workaround:    encode spaces in typolink.parameter
# where to look: typo3conf/ext/perfectlightbox/static/setup.txt 
(overrides for tt_content ... typolink)
#                typo3/sysext/cms/tslib/class.tslib_content.php 
(function typoLink, line: $link_paramA = 
t3lib_div::unQuoteFilenames($link_param, TRUE);)
#                t3lib/class.t3lib_div.php 
(function unQuoteFilenames)
tt_content.image.20.1.imageLinkWrap.typolink.parameter.override.postUserFunc 
= user_SiteFunctions->encodeTypolinkURL# 
typo3/sysext/cms/tslib/class.tslib_content.php (function typoLink)# 
            typo3/sysext/cms/tslib/class.tslib_content.php (function 
typoLink)
tt_content.image.20.1.imageLinkWrap.typolink.parameter.postUserFunc = 
user_SiteFunctions->encodeTypolinkURL
# possibly more calls needed for tt_news (see TypoScript of perfectlightbox)
## WORKAROUND PERFECTLIGHTBOX [END]


user_SiteFunctions: (may need modification)

		function encodeTypolinkURLRegexpCallback($m) {
		    $s = $m[1].$m[2].$m[3];
		    $s = str_replace(' ', '%20', $s);
		    return $s;
		}
		
		function encodeTypolinkURL($s, $conf) {
		    $s = 
preg_replace_callback('/^(fileadmin|typo3temp)(\/.*?\.)(jpe?g|gif|png)/i', 
array($this, 'encodeTypolinkURLRegexpCallback'), $s);
		    return $s;
		}


More information about the TYPO3-english mailing list