2006-05-13 Rob Buis <buis@kde.org>
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 May 2006 15:11:29 +0000 (15:11 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 May 2006 15:11:29 +0000 (15:11 +0000)
        Reviewed by Darin, landed by ap.

        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=8132
        CSS parser sometimes accepts real number as integer

        Add a boolean variable per css value to catch whether values
        are specified as floats or integers.

        Test: fast/css/rgb-float.html

        * css/CSSGrammar.y:
        * css/cssparser.cpp:
        (WebCore::CSSParser::validUnit):
        (WebCore::CSSParser::lex):
        * css/cssparser.h:
        * css/tokenizer.flex:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14352 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css/rgb-float-expected.checksum [new file with mode: 0644]
LayoutTests/fast/css/rgb-float-expected.png [new file with mode: 0644]
LayoutTests/fast/css/rgb-float-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/rgb-float.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/CSSGrammar.y
WebCore/css/cssparser.cpp
WebCore/css/cssparser.h
WebCore/css/tokenizer.flex

index 9e27f41..4e8c7df 100644 (file)
@@ -1,3 +1,15 @@
+2006-05-13  Rob Buis  <buis@kde.org>
+
+        Reviewed by Darin, landed by ap.
+
+        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8132
+        CSS parser sometimes accepts real number as integer
+
+        * fast/css/rgb-float.html: Added.
+        * fast/css/rgb-float-expected.txt: Added.
+        * fast/css/rgb-float-expected.png: Added.
+        * fast/css/rgb-float-expected.checksum: Added.
+
 2006-05-13  Sam Weinig  <sam.weinig@gmail.com>
 
         Reviewed by Hyatt, landed by ap.
diff --git a/LayoutTests/fast/css/rgb-float-expected.checksum b/LayoutTests/fast/css/rgb-float-expected.checksum
new file mode 100644 (file)
index 0000000..80166e5
--- /dev/null
@@ -0,0 +1 @@
+42e883abb1ec53dfb3c9ef467f7abcc4
\ No newline at end of file
diff --git a/LayoutTests/fast/css/rgb-float-expected.png b/LayoutTests/fast/css/rgb-float-expected.png
new file mode 100644 (file)
index 0000000..a0f95f7
Binary files /dev/null and b/LayoutTests/fast/css/rgb-float-expected.png differ
diff --git a/LayoutTests/fast/css/rgb-float-expected.txt b/LayoutTests/fast/css/rgb-float-expected.txt
new file mode 100644 (file)
index 0000000..fa54dc3
--- /dev/null
@@ -0,0 +1,11 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x137
+  RenderBlock {HTML} at (0,0) size 800x137
+    RenderBody {BODY} at (8,21) size 784x95 [color=#008000]
+      RenderBlock {H1} at (0,0) size 784x37
+        RenderText {#text} at (0,0) size 398x37
+          text run at (0,0) width 398: "This should be green, not red"
+      RenderBlock {H1} at (0,58) size 784x37
+        RenderText {#text} at (0,0) size 411x37
+          text run at (0,0) width 411: "This should be green, not blue"
diff --git a/LayoutTests/fast/css/rgb-float.html b/LayoutTests/fast/css/rgb-float.html
new file mode 100644 (file)
index 0000000..8e91e1a
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
+<html lang="en">
+
+<head profile="http://www.ietf.org/rfc/rfc2731.txt">
+
+<title>CSS 2.1 Test Suite: RGB color syntax error handling</title>
+
+<style type="text/css">
+body {color: green;}
+h1#floatnumnum {color: rgb(255.0, 0, 0);}
+h1#numnumfloat {color: rgb(0, 0, 128.0);}
+</style>
+</head>
+
+<body>
+<h1 id="floatnumnum">This should be green, not red</h1>
+<h1 id="numnumfloat">This should be green, not blue</h1>
+</body></html>
+
index b8fb31f..ed88692 100644 (file)
@@ -1,3 +1,22 @@
+2006-05-13  Rob Buis  <buis@kde.org>
+
+        Reviewed by Darin, landed by ap.
+
+        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=8132
+        CSS parser sometimes accepts real number as integer
+
+        Add a boolean variable per css value to catch whether values
+        are specified as floats or integers.
+
+        Test: css2.1/rgb-float.html
+
+        * css/CSSGrammar.y:
+        * css/cssparser.cpp:
+        (WebCore::CSSParser::validUnit):
+        (WebCore::CSSParser::lex):
+        * css/cssparser.h:
+        * css/tokenizer.flex:
+
 2006-05-13  Sam Weinig  <sam.weinig@gmail.com>
 
         Reviewed by Hyatt, landed by ap.
index 2a58c18..969a9f1 100644 (file)
@@ -198,7 +198,8 @@ static int cssyylex(YYSTYPE *yylval) { return CSSParser::current()->lex(yylval);
 %token <val> KHERZ
 %token <string> DIMEN
 %token <val> PERCENTAGE
-%token <val> NUMBER
+%token <val> FLOAT
+%token <val> INTEGER
 
 %token <string> URI
 %token <string> FUNCTION
@@ -923,7 +924,8 @@ term:
   ;
 
 unary_term:
-  NUMBER maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
+  INTEGER maybe_space { $$.id = 0; $$.isInt = true; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
+  | FLOAT maybe_space { $$.id = 0; $$.isInt = false; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
   | PERCENTAGE maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PERCENTAGE; }
   | PXS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PX; }
   | CMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_CM; }
index 6858c72..fb4e466 100644 (file)
@@ -325,8 +325,7 @@ bool CSSParser::validUnit(Value* value, Units unitflags, bool strict)
             value->unit = CSSPrimitiveValue::CSS_PX;
             b = true;
         }
-        if (!b && (unitflags & FInteger) &&
-             (value->fValue - (int)value->fValue) < 0.001)
+        if (!b && (unitflags & FInteger) && value->isInt)
             b = true;
         break;
     case CSSPrimitiveValue::CSS_PERCENTAGE:
@@ -2638,7 +2637,8 @@ int CSSParser::lex(void* yylvalWithoutType)
     case SECS:
     case PERCENTAGE:
         length--;
-    case NUMBER:
+    case FLOAT:
+    case INTEGER:
         yylval->val = DeprecatedString((QChar *)t, length).toDouble();
         break;
 
index fc9cae4..d68a7e2 100644 (file)
@@ -55,6 +55,7 @@ namespace WebCore {
     
     struct Value {
         int id;
+        bool isInt;
         union {
             double fValue;
             int iValue;
index 5b1c74b..c61e80a 100644 (file)
@@ -14,6 +14,7 @@ string2         \'([\t !#$%&(-~]|\\{nl}|\"|{nonascii}|{escape})*\'
 ident           -?{nmstart}{nmchar}*
 name            {nmchar}+
 num             [0-9]+|[0-9]*"."[0-9]+
+intnum          [0-9]+
 string          {string1}|{string2}
 url             ([!#$%&*-~]|{nonascii}|{escape})*
 w               [ \t\r\n\f]*
@@ -70,7 +71,8 @@ range           \?{1,6}|{h}(\?{0,5}|{h}(\?{0,4}|{h}(\?{0,3}|{h}(\?{0,2}|{h}(\??|
 {num}kHz                {yyTok = KHERZ; return yyTok;}
 {num}{ident}            {yyTok = DIMEN; return yyTok;}
 {num}%+                 {yyTok = PERCENTAGE; return yyTok;}
-{num}                   {yyTok = NUMBER; return yyTok;}
+{intnum}                {yyTok = INTEGER; return yyTok;}
+{num}                   {yyTok = FLOAT; return yyTok;}
 
 "url("{w}{string}{w}")" {yyTok = URI; return yyTok;}
 "url("{w}{url}{w}")"    {yyTok = URI; return yyTok;}