jalmenarez / minify

Automatically exported from code.google.com/p/minify
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Incorrect CSS image paths #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Minify version: 2.1.1
PHP version:5.2.4-2ubuntu5.4

What steps will reproduce the problem?
1. Create a css file with a relative image path in it for a background,
such as:
*****
url("../images/fieldset-bg.gif") 
*****
2. Minify the css files with a relative image path in it :
array(
        '//styles/somefile.css'
);

2. Compare the re-written image path in the compressed file:

Expected output:
original: "../images/fieldset-bg.gif"
modified: "../images/fieldset-bg.gif"

Actual output:

original: "../images/fieldset-bg.gif"
modified: "/../images/fieldset-bg.gif" 

Did any unit tests FAIL?

Running test_all.php produces the following failures:
*****
!FAIL: Minify_Cache_File : store (1 of 10 tests run so far have failed)
!FAIL: Minify_Cache_File : isValid (2 of 12 tests run so far have failed)
!FAIL: Minify_Cache_File : display (3 of 13 tests run so far have failed)
!FAIL: Minify_Cache_File : fetch (4 of 14 tests run so far have failed)
!FAIL: Minify_Cache_File : store w/ lock (5 of 15 tests run so far have failed)
!FAIL: Minify_Cache_File : isValid (6 of 17 tests run so far have failed)
!FAIL: Minify_Cache_File : display w/ lock (7 of 18 tests run so far have
failed)
!FAIL: Minify_Cache_File : fetch w/ lock (8 of 19 tests run so far have failed)
!FAIL: environment : PHP/server does not auto-HTTP-encode content (9 of 60
tests run so far have failed)
*****

Please provide any additional information below.

This issue was discussed in brief here:
http://groups.google.com/group/minify/browse_thread/thread/895cb58e4bbfe17

Original issue reported on code.google.com by bmhar...@gmail.com on 26 Jan 2009 at 9:16

GoogleCodeExporter commented 9 years ago
Can you try 2.1.2beta? (upgrade is pretty simple)
http://groups.google.com/group/minify/browse_thread/thread/8add5761eb27d67d

With that in place (and FirePHP logging enabled) we can sprinkle in some 
Minify::logError() in the CSS minifier and figure out what's going wrong.

Original comment by mrclay....@gmail.com on 26 Jan 2009 at 9:43

GoogleCodeExporter commented 9 years ago
Can you run test_environment.php directly to see if it gives more info?
Also, using the test_Minify_Cache_File.php from R283 (just committed) may make 
your 
cache file tests pass. It now uses the path you specify in /min/config.php.

Original comment by mrclay....@gmail.com on 26 Jan 2009 at 10:11

GoogleCodeExporter commented 9 years ago
Trying out 2.1.2beta - got the same results for the url listed above
****
/../images/fieldset-bg.gif
****
 Results of test_environment:

PASS: environment : DOCUMENT_ROOT should not end in trailing slash (1 of 1 
tests run
so far have passed)
PASS: environment : DOCUMENT_ROOT should be real path and contain this test 
file (2
of 2 tests run so far have passed)
!FAIL: environment : PHP/server does not auto-HTTP-encode content (1 of 3 tests 
run
so far have failed)

Returned content should be 6 bytes and not HTTP encoded.
Headers returned by: 
http://berad-ols/min_unit_tests/test_environment.php?hello=1

array (
  0 => 'HTTP/1.1 200 OK',
  1 => 'Date: Mon, 26 Jan 2009 23:03:18 GMT',
  2 => 'Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.4 with Suhosin-Patch',
  3 => 'X-Powered-By: PHP/5.2.4-2ubuntu5.4',
  4 => 'Vary: Accept-Encoding',
  5 => 'Content-Encoding: gzip',
  6 => 'Content-Length: 26',
  7 => 'Connection: close',
  8 => 'Content-Type: text/html',
)

I've got FirePHP all ready to go, let me know if you want me to run anything in
particular, I may dig in a little and see what I can find otherwise.

Original comment by bmhar...@gmail.com on 26 Jan 2009 at 11:03

GoogleCodeExporter commented 9 years ago
After some FirePHP debugging, it looks like its getting the extra "/" placed in 
front
of it on lines 172-173 of CSS.php, which looks like will require some more 
debugging
to see where in _urlCB its happening.  Hopefully that helps somewhat.

Original comment by bmhar...@gmail.com on 26 Jan 2009 at 11:46

GoogleCodeExporter commented 9 years ago
Try this CSS.php. It'll generate 4 messages for each url. If you can't see 
what's 
going on, post em here and I'll walk through it.

Original comment by mrclay....@gmail.com on 27 Jan 2009 at 12:59

Attachments:

GoogleCodeExporter commented 9 years ago
I think I may see what the problem is.  In my setup I have a symbolic link 
called
"static" that goes to a different directory for shared css/js/images across 
projects.
 It looks to me like thats causing the issue around line 300 of the CSS.php patch you
attached as the DOCUMENT_ROOT is not the same as the path to the images in the 
urls.
 I'll think about this a bit, not sure if its possible to figure out the correct path
in this situation or not.  This is definitely a corner case issue.

Here's the output from that:

Minify: $m = array ( 0 => 'url(../images/exclamation.png)', 1 =>
'../images/exclamation.png', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/../images/exclamation.png'
Minify: $m = array ( 0 =>
'url(/static/js/yui/datatable/assets/skins/sam/dt-arrow-up.png)', 1 =>
'/static/js/yui/datatable/assets/skins/sam/dt-arrow-up.png', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/static/js/yui/datatable/assets/skins/sam/dt-arrow-up.png'
Minify: $m = array ( 0 =>
'url(/static/js/yui/datatable/assets/skins/sam/dt-arrow-dn.png)', 1 =>
'/static/js/yui/datatable/assets/skins/sam/dt-arrow-dn.png', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/static/js/yui/datatable/assets/skins/sam/dt-arrow-dn.png'
Minify: $m = array ( 0 => 'url(../images/fieldset-bg.gif)', 1 =>
'../images/fieldset-bg.gif', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/../images/fieldset-bg.gif'
Minify: $m = array ( 0 => 'url(../images/fieldset-bg.gif)', 1 =>
'../images/fieldset-bg.gif', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/../images/fieldset-bg.gif'
Minify: $m = array ( 0 => 'url(../images/fieldset-bg.gif)', 1 =>
'../images/fieldset-bg.gif', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/../images/fieldset-bg.gif'
Minify: $m = array ( 0 => 'url(../images/input-bg.gif)', 1 => 
'../images/input-bg.gif', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/../images/input-bg.gif'
Minify: $m = array ( 0 => 'url(../images/exclamation.png)', 1 =>
'../images/exclamation.png', )
Minify: self::$_tempCurrentDir = '/var/www/static/external/css'
Minify: realpath($_SERVER['DOCUMENT_ROOT']) = '/var/www/online_sales/public'
Minify: $url = '/../images/exclamation.png'

Original comment by bmhar...@gmail.com on 27 Jan 2009 at 3:13

GoogleCodeExporter commented 9 years ago
I've tracked it down to the portion of code in the Files Controller (line 55), 
where
is converts the DOCUMENT_ROOT based file path to the realpath.  This sets up the
filepath to not use the symbolic link, which has the side effects we're seeing 
in the
url rewrite process.

Changing that to not use realpath() and just using $file fixes the issue for 
me, but
I can't say it doesn't cause other regression issues, I need to get all the 
tests
passing locally for me before making the change to know if its causing real 
failures.

Original comment by bmhar...@gmail.com on 27 Jan 2009 at 3:45

GoogleCodeExporter commented 9 years ago
Ok, this might be a workaround: Provide your own CSS minifier function that 
sets/
resets the doc root (so it's the same as the CSS file while the rewriting takes 
place).

// in config.php

function myCssMin($css, $options) {
    require_once 'Minify/CSS.php';
    $_SERVER['DOCUMENT_ROOT'] = '/var/www/static/external/css'; // may have to adjust
    $css = Minify_CSS::minify($css, $options);
    $_SERVER['DOCUMENT_ROOT'] = '/var/www/online_sales/public';
    return $css;
}
$min_serveOptions['minifiers']['text/css'] = 'myCssMin';

...At some point I'm going to rewrite Minify_CSS to use Minify_CSS_UriRewriter, 
which should make rewriting more flexible.

Original comment by mrclay....@gmail.com on 27 Jan 2009 at 4:04

GoogleCodeExporter commented 9 years ago
I'll look at doing something like that, but ultimately I'm wanting to 
minfiy/combine
css files that are in the document_root, and some that are outside (under the 
path of
the symbolic link), so I'm not sure this would handle that.  Thanks for the 
help and
time though, much appreciated!

Original comment by bmhar...@gmail.com on 27 Jan 2009 at 4:22

GoogleCodeExporter commented 9 years ago
Wrapping all the doc roots with realpath() solved issues for a lot of users, 
but 
I'll look into those and see if there would be a non-realpath fix.

I think without having some sort of manual config of symbolic links, this is 
going 
to be impossible to automate in the general case.
hmm...

$min_symlinks = array(
    '/var/www/online_sales/public/css' => '/var/www/static/external/css'
);

Original comment by mrclay....@gmail.com on 27 Jan 2009 at 7:59

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
what happen when I don't want to minify css just combine?
I don't see any uri rewrite happening...

Original comment by cri...@gmail.com on 13 Mar 2009 at 1:02

GoogleCodeExporter commented 9 years ago
@bmharris: Can you try the $min_symlinks option available in 2.1.2?
http://code.google.com/p/minify/source/browse/tags/release_2.1.2/min/config.php#
114

@crirus: See http://code.google.com/p/minify/wiki/UserGuide under "Custom 
Functions". If you have problems with this, please post on the minify list or 
open a 
new issue if you think there is a bug.

Original comment by mrclay....@gmail.com on 13 Mar 2009 at 5:22

GoogleCodeExporter commented 9 years ago
Nice work, that did it for symlinks.

Original comment by bmhar...@gmail.com on 18 Mar 2009 at 2:10