From 7673bbe827338d2863b030cd0c69067558f5aab9 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 24 Jun 2018 10:19:33 -0700 Subject: [PATCH 1/4] only throw on duplicate styles in strict mode --- src/load_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/load_map.cpp b/src/load_map.cpp index 8371a76c7..9c1d0358a 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -545,7 +545,7 @@ void map_parser::parse_style(Map & map, xml_node const& node) if (!map.insert_style(name, std::move(style))) { - if (map.find_style(name)) + if (strict_ && map.find_style(name)) { throw config_error("duplicate style name"); } From 434511ca3b4fbde3723b8780ff78448bcc12cc56 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 24 Jun 2018 19:08:38 -0700 Subject: [PATCH 2/4] fix to only throw in strict mode --- src/load_map.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/load_map.cpp b/src/load_map.cpp index 9c1d0358a..7575cf50d 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -545,11 +545,25 @@ void map_parser::parse_style(Map & map, xml_node const& node) if (!map.insert_style(name, std::move(style))) { - if (strict_ && map.find_style(name)) + boost::optional 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) From c458cf0c57a740713941f860857c03284c644e2d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 26 Jun 2018 09:53:12 -0700 Subject: [PATCH 3/4] test duplicate style throw behavior exactly --- test/standalone/map_xml_test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/standalone/map_xml_test.cpp b/test/standalone/map_xml_test.cpp index d6bc6aac1..caa173ea9 100644 --- a/test/standalone/map_xml_test.cpp +++ b/test/standalone/map_xml_test.cpp @@ -156,6 +156,20 @@ TEST_CASE("map xml I/O") { } } // END SECTION + SECTION("duplicate styles only throw in strict mode") { + std::vector broken_maps; + add_xml_files("test/data/broken_maps", broken_maps); + 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 broken_maps; add_xml_files("test/data/broken_maps", broken_maps); From d60be13ed8483bba8c9ed33ed3fa342b7df1026c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 26 Jun 2018 15:57:21 -0700 Subject: [PATCH 4/4] remove unused code --- test/standalone/map_xml_test.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/standalone/map_xml_test.cpp b/test/standalone/map_xml_test.cpp index caa173ea9..b33a3f718 100644 --- a/test/standalone/map_xml_test.cpp +++ b/test/standalone/map_xml_test.cpp @@ -157,11 +157,8 @@ TEST_CASE("map xml I/O") { } // END SECTION SECTION("duplicate styles only throw in strict mode") { - std::vector broken_maps; - add_xml_files("test/data/broken_maps", broken_maps); 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));