Loading src/plugin.h +20 −3 Changes for src/plugin.h: 20 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -281,10 +281,27 @@ namespace blogi { // attributes, so the legacy attribute drops out of the file on save). inline void splitSpacingShorthand(const std::string &value, std::string &top, std::string &right, std::string &bottom, std::string &left) { // Split on whitespace, but not while inside an unbalanced '(' -- // a single shorthand value is very commonly itself a function // call containing spaces (e.g. "calc(120px / 2) calc(120px / 2)" // is a valid 2-value shorthand, each side its own calc()). // istringstream's operator>> splits on every space regardless, // which shreds each calc() into several bogus fragments (here, // 6 "tokens" instead of 2) and silently corrupts the resulting // per-side values into invalid CSS. std::vector<std::string> parts; std::istringstream iss(value); std::string tok; while (iss >> tok) parts.push_back(tok); std::string cur; int depth = 0; for (char c : value) { if (c == '(') { ++depth; cur += c; } else if (c == ')') { if (depth > 0) --depth; cur += c; } else if (depth == 0 && std::isspace(static_cast<unsigned char>(c))) { if (!cur.empty()) { parts.push_back(cur); cur.clear(); } } else { cur += c; } } if (!cur.empty()) parts.push_back(cur); if (parts.empty()) return; switch (parts.size()) { case 1: top = right = bottom = left = parts[0]; break; Loading Loading
src/plugin.h +20 −3 Changes for src/plugin.h: 20 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -281,10 +281,27 @@ namespace blogi { // attributes, so the legacy attribute drops out of the file on save). inline void splitSpacingShorthand(const std::string &value, std::string &top, std::string &right, std::string &bottom, std::string &left) { // Split on whitespace, but not while inside an unbalanced '(' -- // a single shorthand value is very commonly itself a function // call containing spaces (e.g. "calc(120px / 2) calc(120px / 2)" // is a valid 2-value shorthand, each side its own calc()). // istringstream's operator>> splits on every space regardless, // which shreds each calc() into several bogus fragments (here, // 6 "tokens" instead of 2) and silently corrupts the resulting // per-side values into invalid CSS. std::vector<std::string> parts; std::istringstream iss(value); std::string tok; while (iss >> tok) parts.push_back(tok); std::string cur; int depth = 0; for (char c : value) { if (c == '(') { ++depth; cur += c; } else if (c == ')') { if (depth > 0) --depth; cur += c; } else if (depth == 0 && std::isspace(static_cast<unsigned char>(c))) { if (!cur.empty()) { parts.push_back(cur); cur.clear(); } } else { cur += c; } } if (!cur.empty()) parts.push_back(cur); if (parts.empty()) return; switch (parts.size()) { case 1: top = right = bottom = left = parts[0]; break; Loading