diff --git a/_test/cases/lib/exe/css_css_loadfile.test.php b/_test/cases/lib/exe/css_css_loadfile.test.php new file mode 100644 index 0000000000000000000000000000000000000000..a444d008661fb40846d7e2fbf99963eeea2c788d --- /dev/null +++ b/_test/cases/lib/exe/css_css_loadfile.test.php @@ -0,0 +1,57 @@ +<?php + +require_once DOKU_INC.'lib/exe/css.php'; + +class css_css_loadfile_test extends UnitTestCase { + public function setUp() { + $this->file = tempnam('/tmp', 'css'); + parent::setUp(); + } + + private function csstest($input, $output = null, $location = 'http://www.example.com/') { + io_saveFile($this->file, $input); + $this->assertEqual(css_loadfile($this->file, $location), (is_null($output) ? $input : $output)); + } + + public function test_url_relative() { + $this->csstest('#test { background: url("test/test.png"); }', '#test { background: url("http://www.example.com/test/test.png"); }'); + $this->csstest('#test { background: url(\'test/test.png\'); }', '#test { background: url(\'http://www.example.com/test/test.png\'); }'); + } + + public function test_url_absolute() { + $this->csstest('#test { background: url("/test/test.png"); }'); + $this->csstest('#test { background: url(\'/test/test.png\'); }'); + } + + public function test_url_with_protocol() { + $this->csstest('#test { background: url("http://www.test.com/test/test.png"); }'); + $this->csstest('#test { background: url("https://www.test.com/test/test.png"); }'); + $this->csstest('#test { background: url(\'http://www.test.com/test/test.png\'); }'); + $this->csstest('#test { background: url(\'https://www.test.com/test/test.png\'); }'); + } + + public function test_import_relative() { + $this->csstest('@import "test/test.png";', '@import "http://www.example.com/test/test.png";'); + $this->csstest('@import \'test/test.png\';', '@import \'http://www.example.com/test/test.png\';'); + } + + public function test_import_absolute() { + $this->csstest('@import "/test/test.png";'); + $this->csstest('@import \'/test/test.png\';'); + } + + public function test_import_with_protocol() { + $this->csstest('@import "http://www.test.com/test/test.png";'); + $this->csstest('@import "https://www.test.com/test/test.png";'); + $this->csstest('@import \'http://www.test.com/test/test.png\';'); + $this->csstest('@import \'https://www.test.com/test/test.png\';'); + } + + public function tearDown() { + unlink($this->file); + unset($this->file); + parent::tearDown(); + } +} + +//Setup VIM: ex: et ts=4 sw=4 : diff --git a/lib/exe/css.php b/lib/exe/css.php index eb2d96513e0be6fcfda8756a84e54c165503a047..4db81de0b4835cddc60c2f8b03c56d4ff96b48eb 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -267,8 +267,8 @@ function css_loadfile($file,$location=''){ $css = io_readFile($file); if(!$location) return $css; - $css = preg_replace('#(url\([ \'"]*)((?!/|http://|https://| |\'|"))#','\\1'.$location.'\\3',$css); - $css = preg_replace('#(@import\s+[\'"])((?!/|http://|https://))#', '\\1'.$location.'\\2"', $css); + $css = preg_replace('#(url\([ \'"]*)(?!/|http://|https://| |\'|")#','\\1'.$location,$css); + $css = preg_replace('#(@import\s+[\'"])(?!/|http://|https://)#', '\\1'.$location, $css); return $css; }