Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only throw on duplicate styles in strict mode #3917

Merged
merged 4 commits into from Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/load_map.cpp
Expand Up @@ -545,11 +545,25 @@ void map_parser::parse_style(Map & map, xml_node const& node)

if (!map.insert_style(name, std::move(style)))
{
if (map.find_style(name))
boost::optional<const feature_type_style &> dupe = map.find_style(name);
if (strict_)
{
throw config_error("duplicate style name");
if (dupe)
{
throw config_error("duplicate style name");
}
throw config_error("failed to insert style to the map");
}
else
{
std::string s_err("failed to insert style '");
s_err += name + "' to the map";
if (dupe)
{
s_err += " since it was already added";
}
MAPNIK_LOG_ERROR(load_map) << "map_parser: " << s_err;
}
throw config_error("failed to insert style to the map");
}
}
catch (config_error const& ex)
Expand Down
11 changes: 11 additions & 0 deletions test/standalone/map_xml_test.cpp
Expand Up @@ -156,6 +156,17 @@ TEST_CASE("map xml I/O") {
}
} // END SECTION

SECTION("duplicate styles only throw in strict mode") {
std::string duplicate_stylename("test/data/broken_maps/duplicate_stylename.xml");
CAPTURE(duplicate_stylename);
mapnik::Map m(256, 256);
REQUIRE(m.register_fonts("fonts", true));
REQUIRE_NOTHROW(mapnik::load_map(m, duplicate_stylename, false));
mapnik::Map m2(256, 256);
REQUIRE(m2.register_fonts("fonts", true));
REQUIRE_THROWS(mapnik::load_map(m2, duplicate_stylename, true));
} // END SECTION

SECTION("broken maps") {
std::vector<bfs::path> broken_maps;
add_xml_files("test/data/broken_maps", broken_maps);
Expand Down