jalmenarez / minify

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

Incorrect removal of DOC_ROOT from current path #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Minify version:2.1.1
PHP version:5.2.6

The path is not correctly calculated. This patch fixed my issues.

Index: Minify/CSS.php
===========================================================
========
--- Minify/CSS.php  (revision 13053)
+++ Minify/CSS.php  (working copy)
@@ -282,8 +282,8 @@
                     $path = self::$_tempCurrentDir 
                         . DIRECTORY_SEPARATOR . strtr($url, '/', DIRECTORY_SEPARATOR);
                     // strip doc root
-                    $path = substr($path, 
strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
-                    // fix to absolute URL
+                    $path = substr($path, 
strlen(realpath($_SERVER['DOCUMENT_ROOT'])) - 1);
+           // fix to absolute URL
                     $url = strtr($path, DIRECTORY_SEPARATOR, '/');
                     // remove /./ and /../ where possible
                     $url = str_replace('/./', '/', $url);

Original issue reported on code.google.com by e...@hpuls.no on 18 Nov 2008 at 10:38

GoogleCodeExporter commented 9 years ago
Thanks for the patch. Can you post/e-mail me 
realpath($_SERVER['DOCUMENT_ROOT']) on 
your system? I fear this patch would break working code on hundreds of systems; 
I 
will try it myself and run unit tests when I'm back in town.

Original comment by mrclay....@gmail.com on 18 Nov 2008 at 4:07

GoogleCodeExporter commented 9 years ago
realpath($_SERVER['DOCUMENT_ROOT']) returns '/usr/local/corpwebsite/webroot';

Original comment by e...@hpuls.no on 18 Nov 2008 at 8:12

GoogleCodeExporter commented 9 years ago
Any more information needed regarding this issue?

Original comment by e...@hpuls.no on 4 Dec 2008 at 3:58

GoogleCodeExporter commented 9 years ago
Yes, sorry. I should've asked for more. Could you put this script inside 
DOC_ROOT/
min/ and send me the output?

<?php
header('Content-Type: text/plain');
echo $_SERVER['DOCUMENT_ROOT'], "\n"
     ,realpath($_SERVER['DOCUMENT_ROOT']), "\n"
     ,$_SERVER['SCRIPT_FILENAME'], "\n"
     ,realpath($_SERVER['SCRIPT_FILENAME']), "\n";
?>

Just trying to establish the off-by-one issue that seems to exist only on your 
server. Did you check the unit tests before/after making your change?

Original comment by mrclay....@gmail.com on 4 Dec 2008 at 4:43

GoogleCodeExporter commented 9 years ago
Output of that script was:
/usr/local/corpwebsite/webroot/
/usr/local/corpwebsite/webroot
/usr/local/corpwebsite/webroot/min/docrootest.php
/usr/local/corpwebsite/webroot/min/docrootest.php

I didn't check the unit tests, but will install them and come back with output 
before/after modification.

Original comment by e...@hpuls.no on 4 Dec 2008 at 8:11

GoogleCodeExporter commented 9 years ago
DOCUMENT_ROOT is incorrect in the $_SERVER array (maybe coming from httpd.conf 
or 
vhosts.conf). It's a directory path and should not contain a trailing slash. I 
also 
just ran across a case where DOCROOT was way off. Here's a dirty workaround for 
the 
moment (I'm out of town): In /min/config.php add this code:

// strip '/min/config.php' off the end of __FILE__
$_SERVER['DOCUMENT_ROOT'] = substr(__FILE__, 0, strlen(__FILE__) - 15);

Let me know how this does. I don't know if it can fix the unit tests.

Original comment by mrclay....@gmail.com on 10 Dec 2008 at 1:06

GoogleCodeExporter commented 9 years ago
Ok, the issue was too a DOCROOT set in httpd.conf with a trailing slash.
Even if it's not up to the spec, I suspect that a lot of people have done that, 
and apache doesn't warn on it on 
"configtest" either. Possible solution would be to check if the docroot 
contains trailing slash? 
I have fixed the docroot in the httpd.conf file for my own sites now, but it 
might be useful to include it or 
perhaps add it to the FAQ.

Thanks for all the help, Minify rocks! :)

Original comment by e...@hpuls.no on 11 Dec 2008 at 9:44

GoogleCodeExporter commented 9 years ago
R275 adds a unit test for a properly configured DOCUMENT_ROOT and provides a 
link to 
the above workaround if inproper.

Original comment by mrclay....@gmail.com on 16 Dec 2008 at 5:18

GoogleCodeExporter commented 9 years ago
Hi,

I run min_unit_tests/test_environment.php in my IIS+PHP but after 60 seconds it
returns blank page.

I've checked that DOCUMENT_ROOT is "c:/inetpub/www", but my application is in a
completely different folder "C:/OtherAppsDir/myAppFolder".

Do you know where could I change this? 

Original comment by osca...@gmail.com on 23 Dec 2008 at 11:20

GoogleCodeExporter commented 9 years ago
@oscarml: Comment 6 above has a workaround for fixing 
$_SERVER['DOCUMENT_ROOT']. I'd 
love to know why test_environment.php hung up. Can you check your PHP error 
log? Not 
sure where that would be on IIS.

Original comment by mrclay....@gmail.com on 23 Dec 2008 at 5:24

GoogleCodeExporter commented 9 years ago
In case this helps anyone reading this thread, I use a similar (but generic) 
version 
of the work-around suggested on comment 6:

//----------------
$_SERVER['DOCUMENT_ROOT']=str_replace('\\','/',substr($_SERVER['SCRIPT_FILENAME'
],0,0
-strlen($_SERVER['PHP_SELF'])));
//----------------

And it that doesn't work, you can also try:

//----------------
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', 
'\\', 
$_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
//----------------

I've used it for a while to fix document_root for other php applications on 
windows 
servers... Interestingly enough, the documentation says minify takes case of 
this 
issue on version 2 but that didn't work for me.

Original comment by diego.a...@gmail.com on 22 Apr 2009 at 2:24