From 05546b2053cab41877ffb4d0a46c66c9b51520b0 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Thu, 8 Aug 2019 11:43:37 +0100 Subject: [PATCH] add 'pattern' to unsupported elements + call `handle_unsupported` on end_element to catch them all + update unit tests --- src/svg/svg_parser.cpp | 25 ++++++++----------------- test/unit/svg/svg_parser_test.cpp | 4 +--- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/svg/svg_parser.cpp b/src/svg/svg_parser.cpp index 849aab889..2cc31762f 100644 --- a/src/svg/svg_parser.cpp +++ b/src/svg/svg_parser.cpp @@ -103,7 +103,7 @@ void parse_attr(svg_parser& parser, char const* name, char const* value); namespace { -static std::array const unsupported_elements +static std::array const unsupported_elements { {"symbol"_case, "marker"_case, "view"_case, @@ -111,7 +111,8 @@ static std::array const unsupported_elements "switch"_case, "image"_case, "a"_case, - "clipPath"_case} + "clipPath"_case, + "pattern"_case} }; static std::array const unsupported_attributes @@ -172,6 +173,7 @@ void handle_unsupported(svg_parser& parser, T const& ar, char const* name, char + "> " + std::string(type) + " is not supported")); + break; } } } @@ -387,6 +389,8 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node const* node) break; } case "clipPath"_case: + case "symbol"_case: + case "pattern"_case: { parser.ignore_ = true; break; @@ -399,12 +403,6 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node const* node) case "radialGradient"_case: parse_radial_gradient(parser, node); break; - case "symbol"_case: - parser.ignore_ = true; - break; - case "pattern"_case: - parser.ignore_ = true; - break; } if (!parser.is_defs_) // FIXME @@ -492,17 +490,10 @@ void end_element(svg_parser & parser, rapidxml::xml_node const* node) parser.is_defs_ = false; } } - else if(name == "clipPath"_case) - { - parser.ignore_ = false; - } - else if(name == "symbol"_case) - { - parser.ignore_ = false; - } - else if(name == "pattern"_case) + else if(name == "clipPath"_case || name == "symbol"_case || name == "pattern"_case) { parser.ignore_ = false; + handle_unsupported(parser, unsupported_elements, node->name(), "element"); } } diff --git a/test/unit/svg/svg_parser_test.cpp b/test/unit/svg/svg_parser_test.cpp index 9cd693bef..ef5792629 100644 --- a/test/unit/svg/svg_parser_test.cpp +++ b/test/unit/svg/svg_parser_test.cpp @@ -150,8 +150,7 @@ TEST_CASE("SVG parser") { char const* expected_errors[] = { "SVG parse error: failed to parse with value \"fail\"", - "SVG parse error: failed to parse with value \"fail\"", - "SVG parse error: failed to parse with value \"fail\"" + "SVG parse error: failed to parse with value \"fail\"" }; std::ifstream in(svg_name.c_str()); @@ -189,7 +188,6 @@ TEST_CASE("SVG parser") { "SVG parse error: failed to parse with value \"100invalidunit\"", "SVG parse error: failed to parse ", "SVG parse error: failed to parse with \"fail-path\"", - "SVG parse error: failed to parse with \"fail-path\"", "SVG validation error: invalid radius \"-50\"", "SVG parse error: failed to parse points", "SVG parse error: failed to parse points",