[CSS Grid Layout] Fix grid-template-areas parsing to avoid spaces
[WebKit-https.git] / Source / WebCore / css / CSSParser.cpp
index 584c0c5..b2ca031 100644 (file)
@@ -5961,15 +5961,34 @@ bool CSSParser::parseDashboardRegions(CSSPropertyID propId, bool important)
 #endif /* ENABLE(DASHBOARD_SUPPORT) */
 
 #if ENABLE(CSS_GRID_LAYOUT)
-static bool containsOnlyDots(const String& string)
+static Vector<String> parseGridTemplateAreasColumnNames(const String& gridRowNames)
 {
-    ASSERT(!string.isEmpty());
-    StringImpl& text = *string.impl();
-    for (unsigned i = 0; i < text.length(); ++i) {
-        if (text[i] != '.')
-            return false;
+    ASSERT(!gridRowNames.isEmpty());
+    Vector<String> columnNames;
+    // Using StringImpl to avoid checks and indirection in every call to String::operator[].
+    StringImpl& text = *gridRowNames.impl();
+    unsigned length = text.length();
+    unsigned index = 0;
+    while (index < length) {
+        if (text[index] != ' ' && text[index] != '.') {
+            unsigned gridAreaStart = index;
+            while (index < length && text[index] != ' ' && text[index] != '.')
+                index++;
+            columnNames.append(text.substring(gridAreaStart, index - gridAreaStart));
+            continue;
+        }
+
+        if (text[index] == '.') {
+            while (index < length && text[index] == '.')
+                index++;
+            columnNames.append(".");
+            continue;
+        }
+
+        index++;
     }
-    return true;
+
+    return columnNames;
 }
 
 bool CSSParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const unsigned rowCount, unsigned& columnCount)
@@ -5982,9 +6001,7 @@ bool CSSParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const u
     if (gridRowNames.containsOnlyWhitespace())
         return false;
 
-    Vector<String> columnNames;
-    gridRowNames.split(' ', columnNames);
-
+    Vector<String> columnNames = parseGridTemplateAreasColumnNames(gridRowNames);
     if (!columnCount) {
         columnCount = columnNames.size();
         ASSERT(columnCount);
@@ -5997,7 +6014,7 @@ bool CSSParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const u
         const String& gridAreaName = columnNames[currentColumn];
 
         // Unamed areas are always valid (we consider them to be 1x1).
-        if (containsOnlyDots(gridAreaName))
+        if (gridAreaName == ".")
             continue;
 
         // We handle several grid areas with the same name at once to simplify the validation code.