diff --git a/generator/generator_tests/metadata_test.cpp b/generator/generator_tests/metadata_test.cpp index ddec481b72..fd2056fb9f 100644 --- a/generator/generator_tests/metadata_test.cpp +++ b/generator/generator_tests/metadata_test.cpp @@ -149,6 +149,14 @@ UNIT_TEST(Metadata_ValidateAndFormat_wikipedia) p("wikipedia", "https://en.wikipedia.org/wiki/"); TEST(params.GetMetadata().Empty(), ("Null wiki")); + p("wikipedia", "http://.wikipedia.org/wiki/Whatever"); + TEST(params.GetMetadata().Empty(), ("Null lang", params.GetMetadata().Get(feature::Metadata::FMD_WIKIPEDIA))); + + // We ignore incorrect prefixes + p("wikipedia", "ht.tps://en.wikipedia.org/wiki/Whuh"); + TEST_EQUAL(params.GetMetadata().Get(feature::Metadata::FMD_WIKIPEDIA), "en:Whuh", ("ht.tp:")); + params.GetMetadata().Drop(feature::Metadata::FMD_WIKIPEDIA); + p("wikipedia", "http://ru.google.com/wiki/wutlol"); TEST(params.GetMetadata().Empty(), ("Google")); } diff --git a/generator/osm2meta.hpp b/generator/osm2meta.hpp index e37acb207c..946d75590a 100644 --- a/generator/osm2meta.hpp +++ b/generator/osm2meta.hpp @@ -196,10 +196,8 @@ protected: escaped.fill('0'); escaped << hex; - for (string::const_iterator i = value.cbegin(), n = value.cend(); i != n; ++i) + for (auto const & c : value) { - string::value_type c = (*i); - // Keep alphanumeric and other accepted characters intact // Convert spaces to '_' as wikipedia does // Turn other characters to '%00' sequences @@ -230,7 +228,7 @@ protected: { // Convert URL to "lang:title" i += 3; - string::size_type const j = v.find('.'); + string::size_type const j = v.find('.', i + 1); string const wikiUrlPart = ".wikipedia.org/wiki/"; if (j != string::npos && v.substr(j, wikiUrlPart.length()) == wikiUrlPart) return v.substr(i, j - i) + ":" + v.substr(j + wikiUrlPart.length());