[SCM] WebKit Debian packaging branch, debian/experimental, updated. debian/1.3.8-1-1049-g2e11a8e
yael.aharon at nokia.com
yael.aharon at nokia.com
Fri Jan 21 15:02:17 UTC 2011
The following commit has been merged in the debian/experimental branch:
commit 74e1d44941de29d00cf9354773e9bb6cf6cbdcfe
Author: yael.aharon at nokia.com <yael.aharon at nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Jan 6 16:46:36 2011 +0000
WebCore: document.querySelector(':nth-child(foo)') should throw a syntax error
https://bugs.webkit.org/show_bug.cgi?id=51231
Reviewed by Darin Adler.
Also fixes
CSSNthSelector parsing code is illegible and buggy (allows "n3" as a valid selector)
https://bugs.webkit.org/show_bug.cgi?id=21815
Add a check in the parser that other than an+b, only "odd" or "even" would be allowed
as parameters to nth selector.
Tests: fast/css/css3-nth-tokens-script.html
fast/css/css3-nth-tokens-style.html
* css/CSSGrammar.y:
* css/CSSParser.cpp:
(WebCore::isValidNthToken):
* css/CSSParser.h:
LayoutTests: document.querySelector(':nth-child(foo)') should throw a syntax error
https://bugs.webkit.org/show_bug.cgi?id=51231
CSSNthSelector parsing code is illegible and buggy (allows "n3" as a valid selector)
https://bugs.webkit.org/show_bug.cgi?id=21815
Reviewed by Darin Adler.
* fast/css/css3-nth-tokens-script-expected.txt: Added.
* fast/css/css3-nth-tokens-script.html: Added.
* fast/css/css3-nth-tokens-style-expected.txt: Added.
* fast/css/css3-nth-tokens-style.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75158 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index ad02819..a227fbb 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,17 @@
+2011-01-06 Yael Aharon <yael.aharon at nokia.com>
+
+ Reviewed by Darin Adler.
+
+ document.querySelector(':nth-child(foo)') should throw a syntax error
+ https://bugs.webkit.org/show_bug.cgi?id=51231
+ CSSNthSelector parsing code is illegible and buggy (allows "n3" as a valid selector)
+ https://bugs.webkit.org/show_bug.cgi?id=21815
+
+ * fast/css/css3-nth-tokens-script-expected.txt: Added.
+ * fast/css/css3-nth-tokens-script.html: Added.
+ * fast/css/css3-nth-tokens-style-expected.txt: Added.
+ * fast/css/css3-nth-tokens-style.html: Added.
+
2011-01-06 Andrei Popescu <andreip at google.com>
Unreviewed, build fix.
diff --git a/LayoutTests/fast/css/css3-nth-tokens-script-expected.txt b/LayoutTests/fast/css/css3-nth-tokens-script-expected.txt
new file mode 100644
index 0000000..9b69043
--- /dev/null
+++ b/LayoutTests/fast/css/css3-nth-tokens-script-expected.txt
@@ -0,0 +1,26 @@
+This test passes if the nth-of-type can accept a parameter that is an+b, odd or even. But it does not accept any other parameter.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+debug("These spans should alternate red and green");
+span span span span span span span span
+debug("These spans should alternate red and green");
+span span span span span span span span
+debug("These spans should be black");
+span span span span span span span span
+debug("These spans should be black");
+span span span span span span span span
+
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(255, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(255, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 128, 0)'
+PASS document.querySelector("span.c3:nth-of-type(n3)") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS document.querySelector("span.c3:nth-of-type(foo)") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS document.querySelector("span.c3:nth-of-type(2n3)") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS document.querySelector("span.c3:nth-of-type(foon + bar)") threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/css/css3-nth-tokens-script.html b/LayoutTests/fast/css/css3-nth-tokens-script.html
new file mode 100644
index 0000000..81273ad
--- /dev/null
+++ b/LayoutTests/fast/css/css3-nth-tokens-script.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<style>
+span.c1:nth-of-type(2n -1){ color: red; }
+span.c1:nth-of-type(2n){ color: green; }
+span.c2:nth-of-type(odd){ color: red; }
+span.c2:nth-of-type(even){ color: green; }
+span.c3:nth-of-type(n3){ color: red; }
+span.c3:nth-of-type(foo){ color: green; }
+span.c4:nth-of-type(2n3){ color: red; }
+span.c4:nth-of-type(foon + bar ){ color: green; }
+
+</style>
+
+</head>
+<body>
+<p id="description"></p>
+debug("These spans should alternate red and green");
+<div id="test1"></div>
+debug("These spans should alternate red and green");
+<div id="test2"></div>
+debug("These spans should be black");
+<div id="test3"></div>
+debug("These spans should be black");
+<div id="test4"></div>
+<br>
+<script>
+var i=1;
+for(; i < 5; i++) {
+ var str = "";
+ var j=1;
+ for (; j < 9; j++) {
+ str += '<span class="c' + i + '" id="span' + i + j + '"> span </span>';
+ }
+ document.getElementById("test"+i).innerHTML = str;
+}
+
+</script>
+
+<div id="console"></div>
+<script>
+description('This test passes if the nth-of-type can accept a parameter that is an+b, odd or even. But it does not accept any other parameter.');
+
+el = document.querySelector("span.c1:nth-of-type(2n -1)");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(255, 0, 0)'");
+
+el = document.querySelector("span.c1:nth-of-type(2n)");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 128, 0)'");
+
+el = document.querySelector("span.c2:nth-of-type(odd)");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(255, 0, 0)'");
+
+el = document.querySelector("span.c2:nth-of-type(even)");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 128, 0)'");
+
+shouldThrow('document.querySelector("span.c3:nth-of-type(n3)")', '"Error: SYNTAX_ERR: DOM Exception 12"');
+
+shouldThrow('document.querySelector("span.c3:nth-of-type(foo)")', '"Error: SYNTAX_ERR: DOM Exception 12"');
+
+shouldThrow('document.querySelector("span.c3:nth-of-type(2n3)")', '"Error: SYNTAX_ERR: DOM Exception 12"');
+
+shouldThrow('document.querySelector("span.c3:nth-of-type(foon + bar)")', '"Error: SYNTAX_ERR: DOM Exception 12"');
+
+
+var successfullyParsed = true;
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/css/css3-nth-tokens-style-expected.txt b/LayoutTests/fast/css/css3-nth-tokens-style-expected.txt
new file mode 100644
index 0000000..e8f39e4
--- /dev/null
+++ b/LayoutTests/fast/css/css3-nth-tokens-style-expected.txt
@@ -0,0 +1,26 @@
+This test passes if the nth-of-type can accept a parameter that is an+b, odd or even. But it does not accept any other parameter.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+debug("These spans should alternate red and green");
+span span span span span span span span
+debug("These spans should alternate red and green");
+span span span span span span span span
+debug("These spans should be black");
+span span span span span span span span
+debug("These spans should be black");
+span span span span span span span span
+
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(255, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(255, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('color') is 'rgb(0, 0, 0)'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/css/css3-nth-tokens-style.html b/LayoutTests/fast/css/css3-nth-tokens-style.html
new file mode 100644
index 0000000..6829b49
--- /dev/null
+++ b/LayoutTests/fast/css/css3-nth-tokens-style.html
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<style>
+span.c1:nth-of-type(2n + 1){ color: red; }
+span.c1:nth-of-type(2n - 2){ color: green; }
+span.c2:nth-of-type(odd){ color: red; }
+span.c2:nth-of-type(even){ color: green; }
+span.c3:nth-of-type(n3){ color: red; }
+span.c3:nth-of-type(foo){ color: green; }
+span.c4:nth-of-type(2n3){ color: red; }
+span.c4:nth-of-type(foon + bar ){ color: green; }
+
+</style>
+
+</head>
+<body>
+<p id="description"></p>
+debug("These spans should alternate red and green");
+<div id="test1"></div>
+debug("These spans should alternate red and green");
+<div id="test2"></div>
+debug("These spans should be black");
+<div id="test3"></div>
+debug("These spans should be black");
+<div id="test4"></div>
+<br>
+<script>
+var i=1;
+for(; i < 5; i++) {
+ var str = "";
+ var j=1;
+ for (; j < 9; j++) {
+ str += '<span class="c' + i + '" id="span' + i + j + '"> span </span>';
+ }
+ document.getElementById("test"+i).innerHTML = str;
+}
+
+</script>
+
+<div id="console"></div>
+<script>
+description('This test passes if the nth-of-type can accept a parameter that is an+b, odd or even. But it does not accept any other parameter.');
+
+
+
+el = document.getElementById("span11");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(255, 0, 0)'");
+
+el = document.getElementById("span12");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 128, 0)'");
+
+el = document.getElementById("span21");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(255, 0, 0)'");
+
+el = document.getElementById("span22");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 128, 0)'");
+
+el = document.getElementById("span31");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 0, 0)'");
+
+el = document.getElementById("span32");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 0, 0)'");
+
+el = document.getElementById("span41");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 0, 0)'");
+
+el = document.getElementById("span42");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 0, 0)'");
+
+var successfullyParsed = true;
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 40f9e18..1f83c9e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,25 @@
+2011-01-06 Yael Aharon <yael.aharon at nokia.com>
+
+ Reviewed by Darin Adler.
+
+ document.querySelector(':nth-child(foo)') should throw a syntax error
+ https://bugs.webkit.org/show_bug.cgi?id=51231
+
+ Also fixes
+ CSSNthSelector parsing code is illegible and buggy (allows "n3" as a valid selector)
+ https://bugs.webkit.org/show_bug.cgi?id=21815
+
+ Add a check in the parser that other than an+b, only "odd" or "even" would be allowed
+ as parameters to nth selector.
+
+ Tests: fast/css/css3-nth-tokens-script.html
+ fast/css/css3-nth-tokens-style.html
+
+ * css/CSSGrammar.y:
+ * css/CSSParser.cpp:
+ (WebCore::isValidNthToken):
+ * css/CSSParser.h:
+
2011-01-06 Jan Erik Hanssen <jhanssen at sencha.com>
Reviewed by Andreas Kling.
diff --git a/WebCore/css/CSSGrammar.y b/WebCore/css/CSSGrammar.y
index 207fdf5..ba5855d 100644
--- a/WebCore/css/CSSGrammar.y
+++ b/WebCore/css/CSSGrammar.y
@@ -1205,8 +1205,11 @@ pseudo:
type == CSSSelector::PseudoNthOfType ||
type == CSSSelector::PseudoNthLastChild ||
type == CSSSelector::PseudoNthLastOfType) {
- if (p->document())
- p->document()->setUsesSiblingRules(true);
+ if (isValidNthToken($4)) {
+ if (p->document())
+ p->document()->setUsesSiblingRules(true);
+ } else
+ $$ = 0;
}
}
// used by :not
diff --git a/WebCore/css/CSSParser.cpp b/WebCore/css/CSSParser.cpp
index dd3e38d..0c03b93 100644
--- a/WebCore/css/CSSParser.cpp
+++ b/WebCore/css/CSSParser.cpp
@@ -6309,6 +6309,13 @@ String quoteCSSURLIfNeeded(const String& string)
return isCSSTokenizerURL(string) ? string : quoteCSSString(string);
}
+bool isValidNthToken(const CSSParserString& token)
+{
+ // The tokenizer checks for the construct of an+b.
+ // nth can also accept "odd" or "even" but should not accept any other token.
+ return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even");
+}
+
#define YY_DECL int CSSParser::lex()
#define yyconst const
typedef int yy_state_type;
diff --git a/WebCore/css/CSSParser.h b/WebCore/css/CSSParser.h
index 9015f5b..e60519e 100644
--- a/WebCore/css/CSSParser.h
+++ b/WebCore/css/CSSParser.h
@@ -359,6 +359,7 @@ namespace WebCore {
String quoteCSSStringIfNeeded(const String&);
String quoteCSSURLIfNeeded(const String&);
+ bool isValidNthToken(const CSSParserString&);
} // namespace WebCore
#endif // CSSParser_h
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list