contao/import — Issue #3633: Stylesheets.php incorrect handling of absolute URI when writing to files
Author: importer
Created: 2011-11-29 21:54:13+00:00
State: open
Labels: backend, Defect

Stylesheet.php incorrectly handles absolute URIs when writing to files

e.g. if my css rule looks like this:

background-image: url("http://example.com/files/image.png");

the following will be generated in the css file by contao:

background-image: url("../../http://example.com/files/image.png");

this is due to line 484 of StyleSheets.php:

$glue = (strncmp($row['bgimage'], '/', 1) !== 0) ? $strGlue : '';
$return .= $lb . 'background-image:url("' . $glue . $row['bgimage'] . '");';

here $glue = '../../'; which is changing the URI into something meaningless

the following change will fix this (although its a bit messy - probably a regex better):

$glue = (	strncmp($row['bgimage'], '/', 1) === 0 ||
strncmp($row['bgimage'], 'http://', 7) === 0 ||
strncmp($row['bgimage'], 'https://', 8) === 0 ) ? '' : $strGlue;
$return .= $lb . 'background-image:url("' . $glue . $row['bgimage'] . '");';

the above change will correctly handle the following valid urls:

* http://example.com/files/image.png -> same
* https://example.com/files/image.png -> same
* //example.com/files/image.png -> same
* /files/image.png -> same
* files/image.png -> ../../files/images.png

there are a number of points in Stylesheets.php where this (or a better) correction should be made

hope this all makes sense?

Related issues: #3512

--- _Originally created by wal5hy on November 14th, 2011, at 07:19pm (ID 3633)_