Use GatherURL in ParseNameSpaceRule and ParseImageRect, and rename GatherURL to ParseURLOrString for clarity. (Bug 604179, patch 1) r=bzbarsky

Note that this adds a missing UngetToken(), which affects the other
consumer of GatherURL, parsing of @import rules.
This commit is contained in:
L. David Baron
2011-03-11 11:29:44 -06:00
parent a6108498c3
commit 2cc1b79dee
6 changed files with 55 additions and 40 deletions

View File

@@ -0,0 +1,5 @@
<!DOCTYPE HTML>
<title>Test for unexpected end of @import</title>
<style>div { color: red }</style>
<style>@import ; div { color: green; }</style>
<div>This should be green</div>

View File

@@ -0,0 +1,5 @@
<!DOCTYPE HTML>
<title>Test for unexpected end of @import</title>
<style>div { color: red }</style>
<style>@media ; div { color: green; }</style>
<div>This should be green</div>

View File

@@ -0,0 +1,3 @@
<!DOCTYPE HTML>
<title>Test for unexpected end of @import (reference)</title>
<div style="color: green">This should be green</div>

View File

@@ -2,3 +2,5 @@
== invalid-url-handling.xhtml invalid-url-handling-ref.xhtml
== pseudo-elements-1.html pseudo-elements-1-ref.html
== invalid-attr-1.html invalid-attr-1-ref.html
== at-rule-error-handling-import-1.html at-rule-error-handling-ref.html
== at-rule-error-handling-media-1.html at-rule-error-handling-ref.html

View File

@@ -332,7 +332,7 @@ protected:
PRBool ParseAtRule(RuleAppendFunc aAppendFunc, void* aProcessData);
PRBool ParseCharsetRule(RuleAppendFunc aAppendFunc, void* aProcessData);
PRBool ParseImportRule(RuleAppendFunc aAppendFunc, void* aProcessData);
PRBool GatherURL(nsString& aURL);
PRBool ParseURLOrString(nsString& aURL);
PRBool GatherMedia(nsMediaList* aMedia,
PRBool aInAtRule);
PRBool ParseMediaQuery(PRBool aInAtRule, nsMediaQuery **aQuery,
@@ -1571,7 +1571,7 @@ CSSParserImpl::ParseCharsetRule(RuleAppendFunc aAppendFunc,
}
PRBool
CSSParserImpl::GatherURL(nsString& aURL)
CSSParserImpl::ParseURLOrString(nsString& aURL)
{
if (!GetToken(PR_TRUE)) {
return PR_FALSE;
@@ -1585,6 +1585,7 @@ CSSParserImpl::GatherURL(nsString& aURL)
GetURLInParens(aURL)) {
return PR_TRUE;
}
UngetToken();
return PR_FALSE;
}
@@ -1904,7 +1905,7 @@ CSSParserImpl::ParseImportRule(RuleAppendFunc aAppendFunc, void* aData)
}
nsAutoString url;
if (!GatherURL(url)) {
if (!ParseURLOrString(url)) {
REPORT_UNEXPECTED_TOKEN(PEImportNotURI);
return PR_FALSE;
}
@@ -2105,33 +2106,21 @@ CSSParserImpl::ParseNameSpaceRule(RuleAppendFunc aAppendFunc, void* aData)
if (eCSSToken_Ident == mToken.mType) {
prefix = mToken.mIdent;
// user-specified identifiers are case-sensitive (bug 416106)
if (! GetToken(PR_TRUE)) {
REPORT_UNEXPECTED_EOF(PEAtNSURIEOF);
return PR_FALSE;
}
}
if (eCSSToken_String == mToken.mType) {
url = mToken.mIdent;
if (ExpectSymbol(';', PR_TRUE)) {
ProcessNameSpace(prefix, url, aAppendFunc, aData);
return PR_TRUE;
}
}
else if ((eCSSToken_Function == mToken.mType) &&
(mToken.mIdent.LowerCaseEqualsLiteral("url"))) {
if (GetURLInParens(url) &&
ExpectSymbol(';', PR_TRUE)) {
ProcessNameSpace(prefix, url, aAppendFunc, aData);
return PR_TRUE;
}
}
else {
} else {
UngetToken();
}
REPORT_UNEXPECTED_TOKEN(PEAtNSUnexpected);
return PR_FALSE;
if (!ParseURLOrString(url) || !ExpectSymbol(';', PR_TRUE)) {
if (mHavePushBack) {
REPORT_UNEXPECTED_TOKEN(PEAtNSUnexpected);
} else {
REPORT_UNEXPECTED_EOF(PEAtNSURIEOF);
}
return PR_FALSE;
}
ProcessNameSpace(prefix, url, aAppendFunc, aData);
return PR_TRUE;
}
void
@@ -4752,21 +4741,12 @@ CSSParserImpl::ParseImageRect(nsCSSValue& aImage)
nsCSSValue& bottom = func->Item(4);
nsCSSValue& left = func->Item(5);
if (!GetToken(PR_TRUE))
break;
if (mToken.mType == eCSSToken_String) {
if (!SetValueToURL(url, mToken.mIdent))
break;
} else if (mToken.mType == eCSSToken_Function &&
mToken.mIdent.LowerCaseEqualsLiteral("url")) {
if (!ParseURL(url))
break;
} else {
UngetToken();
nsAutoString urlString;
if (!ParseURLOrString(urlString) ||
!SetValuetoURL(url, urlString) ||
!ExpectSymbol(',', PR_TRUE)) {
break;
}
if (!ExpectSymbol(',', PR_TRUE))
break;
static const PRInt32 VARIANT_SIDE = VARIANT_NUMBER | VARIANT_PERCENT;
if (!ParseNonNegativeVariant(top, VARIANT_SIDE, nsnull) ||

View File

@@ -24,6 +24,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=575672
/** Test for unclosed parentheses in CSS values. **/
// Each of the following semicolon-terminated @-rules should have a
// single missing ')' in the value.
var semirules = [
"@import (",
"@import url(",
"@import url(foo",
"@import url('foo'",
"@import foo(",
];
// Each of the following declarations should have a single missing ')'
// in the value.
var declarations = [
@@ -154,6 +164,16 @@ var textNode = document.createTextNode("");
document.getElementById("style").appendChild(textNode);
var cs = getComputedStyle(document.getElementById("display"), "");
for (var i = 0; i < semirules.length; ++i) {
var sheet = semirules[i] +
"p#display { color: red } ) ; p { color: green; z-index: " + (i + 1) + " }";
textNode.data = sheet;
is(cs.color, "rgb(0, 128, 0)",
"color for rule '" + semirules[i] + "'");
is(cs.zIndex, i+1,
"z-index for rule '" + semirules[i] + "'");
}
for (var i = 0; i < declarations.length; ++i) {
var sheet = "@namespace html url(http://www.w3.org/1999/xhtml);\n" +
"#display { color: green; " + declarations[i] +