add 'pattern' to unsupported elements + call handle_unsupported on end_element to catch them all + update unit tests

This commit is contained in:
Artem Pavlenko 2019-08-08 11:43:37 +01:00
parent f68a147ff4
commit 05546b2053
2 changed files with 9 additions and 20 deletions

View file

@ -103,7 +103,7 @@ void parse_attr(svg_parser& parser, char const* name, char const* value);
namespace {
static std::array<unsigned, 8> const unsupported_elements
static std::array<unsigned, 9> const unsupported_elements
{ {"symbol"_case,
"marker"_case,
"view"_case,
@ -111,7 +111,8 @@ static std::array<unsigned, 8> const unsupported_elements
"switch"_case,
"image"_case,
"a"_case,
"clipPath"_case}
"clipPath"_case,
"pattern"_case}
};
static std::array<unsigned, 43> 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<char> 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<char> 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<char> 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");
}
}

View file

@ -150,8 +150,7 @@ TEST_CASE("SVG parser") {
char const* expected_errors[] =
{
"SVG parse error: failed to parse <color> with value \"fail\"",
"SVG parse error: failed to parse <number> with value \"fail\"",
"SVG parse error: failed to parse <color> with value \"fail\""
"SVG parse error: failed to parse <number> with value \"fail\""
};
std::ifstream in(svg_name.c_str());
@ -189,7 +188,6 @@ TEST_CASE("SVG parser") {
"SVG parse error: failed to parse <number> with value \"100invalidunit\"",
"SVG parse error: failed to parse <path>",
"SVG parse error: failed to parse <path> with <id> \"fail-path\"",
"SVG parse error: failed to parse <path> with <id> \"fail-path\"",
"SVG validation error: invalid <circle> radius \"-50\"",
"SVG parse error: failed to parse <polygon> points",
"SVG parse error: failed to parse <polyline> points",