Ignore:
Timestamp:
Oct 22, 2019, 10:03:34 AM (6 years ago)
Author:
Simon Fraser
Message:

wpt/css/css-images/gradient/color-stops-parsing.html crashes
https://bugs.webkit.org/show_bug.cgi?id=200206

Reviewed by Carlos Alberto Lopez Perez.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-images/gradient/color-stops-parsing-expected.txt:

Source/WebCore:

Share the code that writes color stops, and null-check the stop's m_color.

Tested by http/wpt/css/css-images/gradient/color-stops-parsing.html.

  • css/CSSGradientValue.cpp:

(WebCore::CSSGradientValue::writeColorStop const):
(WebCore::CSSLinearGradientValue::customCSSText const):
(WebCore::CSSRadialGradientValue::customCSSText const):
(WebCore::CSSConicGradientValue::customCSSText const):

  • css/CSSGradientValue.h:

(WebCore::CSSGradientValue::CSSGradientValue):

LayoutTests:

Unskip the test. It fails, but no longer crashes.

  • TestExpectations:
  • imported/w3c/web-platform-tests/css/css-images/gradient/color-stops-parsing-expected.txt: Added.
  • platform/mac-highsierra/imported/w3c/web-platform-tests/css/css-images/gradient/color-stops-parsing-expected.txt: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r249013 r251437  
    680680}
    681681
     682void CSSGradientValue::writeColorStop(StringBuilder& builder, const CSSGradientColorStop& stop) const
     683{
     684    if (!stop.isMidpoint && stop.m_color)
     685        builder.append(stop.m_color->cssText());
     686
     687    if (stop.m_position) {
     688        if (!stop.isMidpoint)
     689            builder.append(' ');
     690        builder.append(stop.m_position->cssText());
     691    }
     692}
     693
    682694String CSSLinearGradientValue::customCSSText() const
    683695{
     
    704716
    705717        for (auto& stop : m_stops) {
    706             result.append(", ", stop.m_color->cssText());
    707             if (stop.m_position)
    708                 result.append(' ', stop.m_position->cssText());
     718            result.appendLiteral(", ");
     719            writeColorStop(result, stop);
    709720        }
    710721    } else {
     
    738749                result.appendLiteral(", ");
    739750            wroteFirstStop = true;
    740             if (!stop.isMidpoint)
    741                 result.append(stop.m_color->cssText());
    742             if (stop.m_position) {
    743                 if (!stop.isMidpoint)
    744                     result.append(' ');
    745                 result.append(stop.m_position->cssText());
    746             }
     751            writeColorStop(result, stop);
    747752        }
    748753    }
     
    955960
    956961        for (auto& stop : m_stops) {
    957             result.append(", ", stop.m_color->cssText());
    958             if (stop.m_position)
    959                 result.append(' ', stop.m_position->cssText());
     962            result.appendLiteral(", ");
     963            writeColorStop(result, stop);
    960964        }
    961965    } else {
     
    10041008            result.appendLiteral(", ");
    10051009
    1006         for (unsigned i = 0; i < m_stops.size(); i++) {
    1007             const CSSGradientColorStop& stop = m_stops[i];
    1008             if (i)
     1010        bool wroteFirstStop = false;
     1011        for (auto& stop : m_stops) {
     1012            if (wroteFirstStop)
    10091013                result.appendLiteral(", ");
    1010             if (!stop.isMidpoint)
    1011                 result.append(stop.m_color->cssText());
    1012             if (stop.m_position) {
    1013                 if (!stop.isMidpoint)
    1014                     result.append(' ');
    1015                 result.append(stop.m_position->cssText());
    1016             }
    1017         }
    1018 
     1014            wroteFirstStop = true;
     1015            writeColorStop(result, stop);
     1016        }
    10191017    }
    10201018
     
    13331331            result.appendLiteral(", ");
    13341332        wroteFirstStop = true;
    1335         if (!stop.isMidpoint)
    1336             result.append(stop.m_color->cssText());
    1337         if (stop.m_position) {
    1338             if (!stop.isMidpoint)
    1339                 result.append(' ');
    1340             result.append(stop.m_position->cssText());
    1341         }
    1342     }
    1343    
     1333        writeColorStop(result, stop);
     1334    }
     1335
    13441336    result.append(')');
    13451337    return result.toString();
Note: See TracChangeset for help on using the changeset viewer.