jalmenarez / minify

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

URI rewriting confused by Userdir setup #96

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Minify version: 2.1.2
PHP version: 5.1.6

What steps will reproduce the problem?
1. Use minimy in a UserDir directory (on Apache).

Expected output:
CSS with correctly preserved URL.

Actual output:
CSS with incorrect URLs.

Did any unit tests FAIL?
No

Please provide any additional information below.

In an (Apache) UserDir setup the filesysten path to the home directory is
typically /home/username/public_html and the URL is example.org/~username
The server/PHP document root can't be used - I guess that's obvious.
However, setting the document root to /home/username/public_html (in
config.php) works OK, except for the relative URLs inside CSS files - they
will be transformed to /file.css instead of /~username/file.css. I don't
see that Minify can fix this automatically (by itself), but I suggest
adding another parameter burl which will be added in front of the path the
Minify normally calculates (based on the given document root). OK, enough
words - and example:

The CSS file: http://home.himolde.no/~nordhaug/css/layout.css
The output from Minify:
http://home.himolde.no/~nordhaug/minify/?f=css/layout.css
Notice how the path to background image is set to /css/menu_bg.jpg instead
of /~nordhaug/css/menu_bg.jpg I'm suggesting fixing this by calling:
http://home.himolde.no/~nordhaug/minify/?f=css&burl=/~nordhaug
I have looked at the Minify source code and I don't think you can achieve
this with the current options in the Minify_CSS class. I didn't see a quick
fix using prepend/rewrite either, but then I don't know Minify well enough.

Have I made myself clear? What do you think?

Original issue reported on code.google.com by hansfn@gmail.com on 5 Mar 2009 at 9:05

GoogleCodeExporter commented 9 years ago
Let's assume your actual doc root is this:
'/home/nordhaug/www'

Add this to config:
$min_symlinks = array(
  '//~nordhaug' => '/home/nordhaug/www'
);

What's $_SERVER['DOCUMENT_ROOT'] in this setup?

Original comment by mrclay....@gmail.com on 5 Mar 2009 at 9:31

GoogleCodeExporter commented 9 years ago
Very close - it's "/home/nordhaug/html" ;-)

Adding the lines you suggested to config.php almost fixed the issue - I now get
"~nordhaug/css/menu_bg.jpg". The leading slash is missing. (I read about 
symlinks,
but didn't see that it could be used like this.)

$_SERVER['DOCUMENT_ROOT'] is /home/httpd/html

PS! Thanks for the quick replies.

Original comment by hansfn@gmail.com on 5 Mar 2009 at 9:49

GoogleCodeExporter commented 9 years ago
Hmm, make sure that your docRoot doesn't end with a slash; that will cause 
missing 
leading slashes.

Or it's possible my symlink code has an off-by-one bug. I need to write a unit 
test 
for it.

The symlinks feature just allows the URI rewriter to "unresolve" real file 
paths 
(e.g. /home/nordhaug/html/myFile) back into fake ones (e.g. /home/nordhaug/html/
~nordhaug/myFile), so then when you strip off the leading docRoot, you get the 
correct root-relative URI (/~nordhaug/myFile).

Original comment by mrclay....@gmail.com on 6 Mar 2009 at 12:24

GoogleCodeExporter commented 9 years ago
Then it must be a off-by-one bug, because I did double-check the trailing 
slash. I
have symlinked config.php to config.phps so you can verify for yourself:
http://home.himolde.no/~nordhaug/minify/config.phps

Original comment by hansfn@gmail.com on 6 Mar 2009 at 12:39

GoogleCodeExporter commented 9 years ago
It's a off-by-one bug.
http://code.google.com/p/minify/source/browse/tags/release_2.1.2/min/lib/Minify/
CSS/
UriRewriter.php#55

Line 55 should be:
$link = str_replace('//', realpath(self::$_docRoot) . '/', $link);

Does this fix for you?

Original comment by mrclay....@gmail.com on 6 Mar 2009 at 1:14

GoogleCodeExporter commented 9 years ago
No, because the symlink is apperently already expanded at this point. I added 
some
echo statements to display the value of $link in that foreach loop - see
http://home.himolde.no/~nordhaug/minify/?f=css/layout.css
(I inserted a die() after the loop - if you wondered why the CSS didn't 
display.)

Original comment by hansfn@gmail.com on 6 Mar 2009 at 1:42

GoogleCodeExporter commented 9 years ago
Oops. You need both these changes: 
http://code.google.com/p/minify/source/detail?r=302

Original comment by mrclay....@gmail.com on 6 Mar 2009 at 2:44

GoogleCodeExporter commented 9 years ago
Thx, that did the trick. It wasn't a UserDir issues, but at least we got 
another bug
fixed.

Hans

Original comment by hansfn@gmail.com on 6 Mar 2009 at 6:18

GoogleCodeExporter commented 9 years ago

Original comment by mrclay....@gmail.com on 19 Mar 2009 at 4:46

GoogleCodeExporter commented 9 years ago

Original comment by mrclay....@gmail.com on 19 Mar 2009 at 4:48