Merge pull request #3917 from mapnik/only-throw-on-dupe-style-in-strict-mode

Only throw on duplicate styles in strict mode
This commit is contained in:
Dane Springmeyer 2018-06-26 18:20:35 -07:00 committed by GitHub
commit 42d3f2d0d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View file

@ -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)

View file

@ -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);