Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArsentiy Milchakov <a.milchakov@corp.mail.ru>2016-08-17 13:16:27 +0300
committerArsentiy Milchakov <a.milchakov@corp.mail.ru>2016-08-17 13:16:27 +0300
commit3827b9871217ce4029e893eb178650cd71a03e78 (patch)
tree5dcdddd2bfe84e7c57163465b010d11b5e295e08 /indexer/editable_map_object.cpp
parent8add28eba33004c47bed783e0ce54a8c5501b6a8 (diff)
website validation corrections
Diffstat (limited to 'indexer/editable_map_object.cpp')
-rw-r--r--indexer/editable_map_object.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/indexer/editable_map_object.cpp b/indexer/editable_map_object.cpp
index 56a26b7194..40af906d33 100644
--- a/indexer/editable_map_object.cpp
+++ b/indexer/editable_map_object.cpp
@@ -52,6 +52,19 @@ size_t PushMwmLanguages(StringUtf8Multilang const & names, vector<int8_t> const
return count;
}
+
+string const kWebSiteProtocols[] = {"http://", "https://"};
+string const kWebSiteProtocolByDefault = "http://";
+
+bool IsProtocolSpecified(string const & website)
+{
+ for (auto const & protocol : kWebSiteProtocols)
+ {
+ if (strings::StartsWith(website, protocol.c_str()))
+ return true;
+ }
+ return false;
+}
} // namespace
namespace osm
@@ -267,12 +280,9 @@ void EditableMapObject::SetEmail(string const & email)
void EditableMapObject::SetWebsite(string website)
{
- if (!website.empty() &&
- !strings::StartsWith(website, "http://") &&
- !strings::StartsWith(website, "https://"))
- {
- website = "http://" + website;
- }
+ if (!website.empty() && !IsProtocolSpecified(website))
+ website = kWebSiteProtocolByDefault + website;
+
m_metadata.Set(feature::Metadata::FMD_WEBSITE, website);
m_metadata.Drop(feature::Metadata::FMD_URL);
}
@@ -443,8 +453,21 @@ bool EditableMapObject::ValidateWebsite(string const & site)
if (site.empty())
return true;
+ size_t startPos = 0;
+ for (auto const & protocol : kWebSiteProtocols)
+ {
+ if (strings::StartsWith(site, protocol.c_str()))
+ {
+ startPos = protocol.size();
+ break;
+ }
+ }
+
+ if (startPos >= site.size())
+ return false;
+
// Site should contain at least one dot but not at the begining/end.
- if ('.' == site.front() || '.' == site.back())
+ if ('.' == site[startPos] || '.' == site.back())
return false;
if (string::npos == site.find("."))