mirror of
https://github.com/mrclay/minify.git
synced 2025-08-22 21:52:58 +02:00
HTTP/Encoder.php : by default no longer encodes to IE6, + setting to do so
importProcessor/output.css : fixed to work portably
This commit is contained in:
@@ -36,6 +36,23 @@
|
|||||||
*/
|
*/
|
||||||
class HTTP_Encoder {
|
class HTTP_Encoder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the encoder allow HTTP encoding to IE6?
|
||||||
|
*
|
||||||
|
* If you have many IE6 users and the bandwidth savings is worth troubling
|
||||||
|
* some of them, set this to true.
|
||||||
|
*
|
||||||
|
* By default, encoding is only offered to IE7+. When this is true,
|
||||||
|
* getAcceptedEncoding() will return an encoding for IE6 if its user agent
|
||||||
|
* string contains "SV1". This has been documented in many places as "safe",
|
||||||
|
* but there seem to be remaining, intermittent encoding bugs in patched
|
||||||
|
* IE6 on the wild web.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public static $encodeToIe6 = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default compression level for zlib operations
|
* Default compression level for zlib operations
|
||||||
*
|
*
|
||||||
@@ -44,6 +61,7 @@ class HTTP_Encoder {
|
|||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public static $compressionLevel = 6;
|
public static $compressionLevel = 6;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an HTTP Encoder object
|
* Get an HTTP Encoder object
|
||||||
@@ -258,9 +276,8 @@ class HTTP_Encoder {
|
|||||||
}
|
}
|
||||||
// no regex = faaast
|
// no regex = faaast
|
||||||
$version = (float)substr($ua, 30);
|
$version = (float)substr($ua, 30);
|
||||||
return (
|
return self::$encodeToIe6
|
||||||
$version < 6
|
? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1')))
|
||||||
|| ($version == 6 && false === strpos($ua, 'SV1'))
|
: ($version < 7);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
@media screen {
|
@media screen {
|
||||||
/* some CSS to try to exercise things in general */
|
/* some CSS to try to exercise things in general */
|
||||||
|
|
||||||
@import url(/_3rd_party/minify/min_extras/unit_tests/_test_files/css/more.css);
|
@import url(%TEST_FILES_URI%/css/more.css);
|
||||||
|
|
||||||
body, td, th {
|
body, td, th {
|
||||||
font-family: Verdana , "Bitstream Vera Sans" , sans-serif ;
|
font-family: Verdana , "Bitstream Vera Sans" , sans-serif ;
|
||||||
@@ -32,17 +32,17 @@ h1 + p {
|
|||||||
}
|
}
|
||||||
@import url(http://example.com/hello.css);
|
@import url(http://example.com/hello.css);
|
||||||
adjacent foo { background: red url(/red.gif); }
|
adjacent foo { background: red url(/red.gif); }
|
||||||
adjacent bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/../green.gif') }
|
adjacent bar { background: url('%TEST_FILES_URI%/importProcessor/../green.gif') }
|
||||||
}
|
}
|
||||||
|
|
||||||
@media tv,projection {
|
@media tv,projection {
|
||||||
/* @import url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/1/bad.css') bad; */
|
/* @import url('%TEST_FILES_URI%/importProcessor/1/bad.css') bad; */
|
||||||
adjacent2 foo { background: red url(/red.gif); }
|
adjacent2 foo { background: red url(/red.gif); }
|
||||||
adjacent2 bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/1/../green.gif') }
|
adjacent2 bar { background: url('%TEST_FILES_URI%/importProcessor/1/../green.gif') }
|
||||||
@import '../input.css';
|
@import '../input.css';
|
||||||
tv foo { background: red url(/red.gif); }
|
tv foo { background: red url(/red.gif); }
|
||||||
tv bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/1/../green.gif') }
|
tv bar { background: url('%TEST_FILES_URI%/importProcessor/1/../green.gif') }
|
||||||
}
|
}
|
||||||
|
|
||||||
input foo { background: red url(/red.gif); }
|
input foo { background: red url(/red.gif); }
|
||||||
input bar { background: url('/_3rd_party/minify/min_extras/unit_tests/_test_files/importProcessor/../green.gif') }
|
input bar { background: url('%TEST_FILES_URI%/importProcessor/../green.gif') }
|
@@ -7,6 +7,7 @@ function test_HTTP_Encoder()
|
|||||||
{
|
{
|
||||||
global $thisDir;
|
global $thisDir;
|
||||||
|
|
||||||
|
HTTP_Encoder::$encodeToIe6 = true;
|
||||||
$methodTests = array(
|
$methodTests = array(
|
||||||
array(
|
array(
|
||||||
'ua' => 'Any browser'
|
'ua' => 'Any browser'
|
||||||
@@ -51,7 +52,28 @@ function test_HTTP_Encoder()
|
|||||||
,'desc' => 'Opera identifying as IE6'
|
,'desc' => 'Opera identifying as IE6'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
foreach ($methodTests as $test) {
|
||||||
|
$_SERVER['HTTP_USER_AGENT'] = $test['ua'];
|
||||||
|
$_SERVER['HTTP_ACCEPT_ENCODING'] = $test['ae'];
|
||||||
|
$exp = $test['exp'];
|
||||||
|
$ret = HTTP_Encoder::getAcceptedEncoding();
|
||||||
|
$passed = assertTrue($exp == $ret, 'HTTP_Encoder : ' . $test['desc']);
|
||||||
|
|
||||||
|
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||||
|
echo "\n--- AE | UA = {$test['ae']} | {$test['ua']}\n";
|
||||||
|
echo "Expected = " . preg_replace('/\\s+/', ' ', var_export($exp, 1)) . "\n";
|
||||||
|
echo "Returned = " . preg_replace('/\\s+/', ' ', var_export($ret, 1)) . "\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HTTP_Encoder::$encodeToIe6 = false;
|
||||||
|
$methodTests = array(
|
||||||
|
array(
|
||||||
|
'ua' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
|
||||||
|
,'ae' => 'gzip, deflate'
|
||||||
|
,'exp' => array('', '')
|
||||||
|
,'desc' => 'IE6 w/ "enhanced security"'
|
||||||
|
)
|
||||||
|
);
|
||||||
foreach ($methodTests as $test) {
|
foreach ($methodTests as $test) {
|
||||||
$_SERVER['HTTP_USER_AGENT'] = $test['ua'];
|
$_SERVER['HTTP_USER_AGENT'] = $test['ua'];
|
||||||
$_SERVER['HTTP_ACCEPT_ENCODING'] = $test['ae'];
|
$_SERVER['HTTP_ACCEPT_ENCODING'] = $test['ae'];
|
||||||
|
Reference in New Issue
Block a user