JohannesKreuzer / minify

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

URL rewriting when minifying css file outside document root #303

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
While minifying a bootstrap library css file I noticed that if file is not 
under document root and not symlinked in document root the url rewriter blindly 
fails trying to remove document root path from absolute url.

Minify commit/version: 2.1.7
PHP version: any

What steps will reproduce the problem?

groupsConfig.php:

return array(
  'test2.css'=> array ( 
    '/var/h/lib/bootstrap-3.0.3/css/test.css',
  )
);

test.css:

@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('../fonts/glyphicons-halflings-regular.eot');
}

debug output:

/* Minify_CSS_UriRewriter::$debugText

docRoot    : /var/www/www.example.org/public_html
currentDir : /var/h/lib/bootstrap-3.0.3/css

file-relative URI  : ../fonts/glyphicons-halflings-regular.eot
path prepended     : 
/var/h/lib/bootstrap-3.0.3/css/../fonts/glyphicons-halflings-regular.eot
docroot stripped   : hicons-halflings-regular.eot <<<<<------- DOCROOT SHOULD 
NOT BE STRIPPED AS PATH WAS ABSOLUTE
traversals removed : hicons-halflings-regular.eot 

*/

/* test.css */

/* 1 */ 
/* 2 */ @font-face {
/* 3 */   font-family: 'Glyphicons Halflings';
/* 4 */   src: url('hicons-halflings-regular.eot');
/* 5 */ }
/* 6 */ 

I could not find any documentation about wether or not it should be possible to 
minify files out of document root, but a possible easy solution would be to 
modify UriRewriter line 163:

        // strip doc root
        $path = substr($path, strlen($realDocRoot));

to check if $path contains $realDocRoot before cutting it.

Original issue reported on code.google.com by lui...@gmail.com on 26 Dec 2013 at 10:46

GoogleCodeExporter commented 8 years ago
After a bit experimenting, there is no use in generating correct paths outside 
of document root.
Even if we were able to generate the correct path in the example, the fonts 
would not be available as they are not reachable by the web server.

However, I still think this is a bug since min generated a wrong truncated path 
without any error or notice.

Original comment by lui...@gmail.com on 26 Dec 2013 at 3:29

GoogleCodeExporter commented 8 years ago
You must configure Minify to handle URLs served from outside the docroot.
http://code.google.com/p/minify/wiki/UriRewriting#Aliases_/_Symlinks_/_Virtual_D
irectories

Original comment by mrclay....@gmail.com on 26 Dec 2013 at 4:37