summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/text/qcssparser.cpp9
-rw-r--r--tests/auto/gui/text/qcssparser/tst_qcssparser.cpp5
2 files changed, 8 insertions, 6 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index f67c0f485a..24ad9d5092 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -770,11 +770,14 @@ static ColorData parseColorValue(QCss::Value v)
if (tokenCount < 5)
return ColorData();
- // ### Qt6: replace this with a check and return invalid color when token count does not match
- if (hasAlpha && tokenCount != 7)
+ if (hasAlpha && tokenCount != 7) {
qWarning("QCssParser::parseColorValue: Specified color with alpha value but no alpha given: '%s'", qPrintable(lst.join(QLatin1Char(' '))));
- if (!hasAlpha && tokenCount != 5)
+ return ColorData();
+ }
+ if (!hasAlpha && tokenCount != 5) {
qWarning("QCssParser::parseColorValue: Specified color without alpha value but alpha given: '%s'", qPrintable(lst.join(QLatin1Char(' '))));
+ return ColorData();
+ }
int v1 = colorDigits.at(0).variant.toInt();
int v2 = colorDigits.at(2).variant.toInt();
diff --git a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
index 0c7e53b4fa..937e7c2acd 100644
--- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
+++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
@@ -860,9 +860,8 @@ void tst_QCssParser::colorValue_data()
QTest::newRow("role2") << "color: palette( window-text ) " << qApp->palette().color(QPalette::WindowText);
QTest::newRow("transparent") << "color: transparent" << QColor(Qt::transparent);
- // ### Qt6: no longer valid
- QTest::newRow("rgb-invalid") << "color: rgb(10, 20, 30, 40)" << QColor(10, 20, 30, 40);
- QTest::newRow("rgba-invalid") << "color: rgba(10, 20, 30)" << QColor(10, 20, 30, 255);
+ QTest::newRow("rgb-invalid") << "color: rgb(10, 20, 30, 40)" << QColor();
+ QTest::newRow("rgba-invalid") << "color: rgba(10, 20, 30)" << QColor();
}
void tst_QCssParser::colorValue()