1
0
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:
Steve Clay
2008-09-02 18:10:21 +00:00
parent a45e4a3d8d
commit e31e9299a5
3 changed files with 50 additions and 11 deletions

View File

@@ -36,6 +36,23 @@
*/
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
*
@@ -45,6 +62,7 @@ class HTTP_Encoder {
*/
public static $compressionLevel = 6;
/**
* Get an HTTP Encoder object
*
@@ -258,9 +276,8 @@ class HTTP_Encoder {
}
// no regex = faaast
$version = (float)substr($ua, 30);
return (
$version < 6
|| ($version == 6 && false === strpos($ua, 'SV1'))
);
return self::$encodeToIe6
? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1')))
: ($version < 7);
}
}

View File

@@ -1,7 +1,7 @@
@media screen {
/* 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 {
font-family: Verdana , "Bitstream Vera Sans" , sans-serif ;
@@ -32,17 +32,17 @@ h1 + p {
}
@import url(http://example.com/hello.css);
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 {
/* @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 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';
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 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') }

View File

@@ -7,6 +7,7 @@ function test_HTTP_Encoder()
{
global $thisDir;
HTTP_Encoder::$encodeToIe6 = true;
$methodTests = array(
array(
'ua' => 'Any browser'
@@ -51,7 +52,28 @@ function test_HTTP_Encoder()
,'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) {
$_SERVER['HTTP_USER_AGENT'] = $test['ua'];
$_SERVER['HTTP_ACCEPT_ENCODING'] = $test['ae'];