Commit 11874d15 authored by jan.koester's avatar jan.koester
Browse files

svg fix

parent f8b2aec2
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -910,7 +910,7 @@ void libhtmlpp::HtmlElement::remove(libhtmlpp::Element* el){
 * @throws HTMLException if no tag could be determined.
 */

void libhtmlpp::HtmlElement::_serialelize(const std::vector<char>& in) {
void libhtmlpp::HtmlElement::_serialelize(const std::vector<char>& in, bool preserveAttrCase) {
    _TagName.clear();

    auto is_space = [](unsigned char c) -> bool {
@@ -984,7 +984,9 @@ void libhtmlpp::HtmlElement::_serialelize(const std::vector<char>& in) {
        }

        std::string key(in.begin() + kstart, in.begin() + kend);
        if (!preserveAttrCase) {
            for (char& ch : key) ch = static_cast<char>(tolower_ascii(static_cast<unsigned char>(ch)));
        }

        while (i < r && is_space(static_cast<unsigned char>(in[i]))) ++i;

@@ -1753,15 +1755,21 @@ size_t libhtmlpp::SvgElement::parseElement(const std::vector<char>& in,
    {
        std::vector<char> tel;
        tel.assign(begin + startel, it_close_angle);
        svgEl->_serialelize(tel);
        svgEl->_serialelize(tel, /*preserveAttrCase=*/true);
    }

    auto it_content_begin = it_close_angle;
    if (it_content_begin != in.end()) ++it_content_begin; // safe increment

    static constexpr char kEndTag[] = "</svg>";
    auto ci_eq = [](char a, char b) {
        auto lower = [](unsigned char c) -> unsigned char {
            return (c >= 'A' && c <= 'Z') ? static_cast<unsigned char>(c + 32) : c;
        };
        return lower(static_cast<unsigned char>(a)) == lower(static_cast<unsigned char>(b));
    };
    auto it_end = std::search(it_content_begin, in.end(),
                              std::begin(kEndTag), std::end(kEndTag) - 1 /* no '\0' */);
                              std::begin(kEndTag), std::end(kEndTag) - 1 /* no '\0' */, ci_eq);
    if (it_end == in.end()) {
        HTMLException excp;
        throw excp[HTMLException::Error] << "Parsing error: Missing </svg> closing tag.";
+4 −1
Original line number Diff line number Diff line
@@ -168,7 +168,10 @@ namespace libhtmlpp {

        std::unique_ptr<Element>  _childElement=nullptr;

        void _serialelize(const std::vector<char> &in);
        // preserveAttrCase: skip lowercasing attribute keys (SVG's own attributes
        // like viewBox/preserveAspectRatio are case-sensitive per the XML/SVG spec,
        // unlike regular HTML attributes).
        void _serialelize(const std::vector<char> &in, bool preserveAttrCase = false);
    private:
        //if text tagname must be zero
        std::vector<char> _TagName;