Bug 462458. Update @charset detection to spec changes. r+sr=dbaron, a=beltzner

This commit is contained in:
Boris Zbarsky 2008-11-11 22:36:20 -05:00
parent 695687d1fe
commit 091edfd4c7
24 changed files with 162 additions and 22 deletions

View File

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<body style="color: green">
This should be green
</body>
<html>

View File

@ -0,0 +1,10 @@
== test-attribute.html pass.html
== test-charset-quotes.html pass.html
== test-charset-leading-space.html pass.html
== test-charset-trailing-space.html pass.html
== test-charset-utf-16-le-no-bom.html pass.html
fails == test-charset-utf-16-le-bom.html pass.html
== test-charset-utf-16-bom-le.html pass.html
== test-charset-utf-16-be-no-bom.html pass.html
fails == test-charset-utf-16-be-bom.html pass.html
== test-charset-utf-16-bom-be.html pass.html

Binary file not shown.

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: red; }
</style>
<link rel="stylesheet" type="text/css" charset="UTF-16BE"
href="test-attribute.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: green; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-leading-space.css">
</head>
<body>
This should be green
</body>
<html>

Binary file not shown.

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: green; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-quotes.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: green; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-trailing-space.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: green; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-utf-16-be-bom.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: red; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-utf-16-be-no-bom.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: red; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-utf-16-bom-be.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: red; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-utf-16-bom-le.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: green; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-utf-16-le-bom.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { color: red; }
</style>
<link rel="stylesheet" type="text/css" charset="us-ascii"
href="test-charset-utf-16-le-no-bom.css">
</head>
<body>
This should be green
</body>
<html>

View File

@ -35,6 +35,9 @@ include canvas/reftest.list
# css @import tests
include css-import/reftest.list
# css character encoding tests
include css-charset/reftest.list
# columns/
include columns/reftest.list

View File

@ -445,7 +445,7 @@ CSSLoaderImpl::RecycleParser(nsICSSParser* aParser)
return NS_OK;
}
static const char kCharsetSym[] = "@charset";
static const char kCharsetSym[] = "@charset \"";
static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
PRUint32 aDataLength,
@ -576,25 +576,9 @@ static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
pos += step;
}
while (pos < aDataLength && nsCRT::IsAsciiSpace(aStyleSheetData[pos])) {
pos += step;
}
if (pos >= aDataLength ||
(aStyleSheetData[pos] != '"' && aStyleSheetData[pos] != '\'')) {
return aCharset.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK;
}
char quote = aStyleSheetData[pos];
pos += step;
nsCAutoString charset;
while (pos < aDataLength) {
if (aStyleSheetData[pos] == '\\') {
pos += step;
if (pos >= aDataLength) {
break;
}
} else if (aStyleSheetData[pos] == quote) {
if (aStyleSheetData[pos] == '"') {
break;
}
@ -605,10 +589,6 @@ static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
// Check for the ending ';'
pos += step;
while (pos < aDataLength && nsCRT::IsAsciiSpace(aStyleSheetData[pos])) {
pos += step;
}
if (pos >= aDataLength || aStyleSheetData[pos] != ';') {
return aCharset.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK;
}