From 487f9f060e79019a898ba445d17ceff56510a666 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Mon, 23 Aug 2021 11:45:06 +0300 Subject: [PATCH] Fix css rule declaration splitting --- nel/src/gui/css_parser.cpp | 62 +++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/nel/src/gui/css_parser.cpp b/nel/src/gui/css_parser.cpp index d4980784a..dcc82dfc6 100644 --- a/nel/src/gui/css_parser.cpp +++ b/nel/src/gui/css_parser.cpp @@ -41,25 +41,57 @@ namespace NLGUI TStyleVec CCssParser::parseDecls(const std::string &styleString) { TStyleVec styles; - std::vector elements; - NLMISC::splitString(styleString, ";", elements); - - for(uint i = 0; i < elements.size(); ++i) + size_t pos = 0; + size_t end = styleString.size(); + while(pos < end) { - std::string::size_type pos; - pos = elements[i].find_first_of(':'); - if (pos != std::string::npos) + size_t sep = styleString.find(':', pos); + if (sep == std::string::npos) + break; + + size_t keyIndex = pos; + size_t keyLength = sep - pos; + + sep++; + pos = sep; + while(sep < end) { - // css properties are case-insensitive, but - // custom properties (--name; ...;) are case sensitive - std::string key = trim(elements[i].substr(0, pos)); - if (key.size() < 2 || (key[0] != '-' && key[1] != '-')) - key = toLowerAscii(key); - std::string value = trim(elements[i].substr(pos+1)); - styles.push_back(TStylePair(key, value)); + sep = styleString.find_first_of(";'\"(", sep); + if (sep == std::string::npos || styleString[sep] == ';') + break; + + if (styleString[sep] == '\'' || styleString[sep] == '"') + { + char ch = styleString[sep]; + // skip open quote + sep++; + while(sep < end && styleString[sep] != ch) + { + if (styleString[sep] == '\\') + sep++; + sep++; + } + // skip close quote + sep++; + } + else if (styleString[sep] == '(') + { + while(sep < end && styleString[sep] != ')') + { + sep++; + } + // skip close parenthesis + sep++; + } } - } + styles.push_back(TStylePair(trim(styleString.substr(keyIndex, keyLength)), trim(styleString.substr(pos, sep - pos)))); + + if (sep >= end) + break; + + pos = sep + 1; + } return styles; }