mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[editor] Check OSM max char length in value validation
Signed-off-by: map-per <map-per@gmx.de>
This commit is contained in:
@@ -243,14 +243,11 @@ void ChangesetWrapper::Modify(editor::XMLFeature node)
|
|||||||
|
|
||||||
void ChangesetWrapper::AddChangesetTag(std::string key, std::string value)
|
void ChangesetWrapper::AddChangesetTag(std::string key, std::string value)
|
||||||
{
|
{
|
||||||
value = strings::EscapeForXML(value);
|
// Truncate to 254 characters as OSM has a length limit of 255
|
||||||
|
if (strings::Truncate(value, kMaximumOsmChars))
|
||||||
|
value += "…";
|
||||||
|
|
||||||
//OSM has a length limit of 255 characters
|
value = strings::EscapeForXML(value);
|
||||||
if (value.length() > kMaximumOsmChars)
|
|
||||||
{
|
|
||||||
LOG(LWARNING, ("value is too long for OSM 255 char limit: ", value));
|
|
||||||
value = value.substr(0, kMaximumOsmChars - 3).append("...");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_changesetComments.insert_or_assign(std::move(key), std::move(value));
|
m_changesetComments.insert_or_assign(std::move(key), std::move(value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -479,6 +479,9 @@ bool EditableMapObject::CheckHouseNumberWhenIsAddress() const
|
|||||||
// static
|
// static
|
||||||
bool EditableMapObject::ValidateFlats(string const & flats)
|
bool EditableMapObject::ValidateFlats(string const & flats)
|
||||||
{
|
{
|
||||||
|
if (strings::CountChar(flats) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
for (auto it = strings::SimpleTokenizer(flats, ";"); it; ++it)
|
for (auto it = strings::SimpleTokenizer(flats, ";"); it; ++it)
|
||||||
{
|
{
|
||||||
string_view token = *it;
|
string_view token = *it;
|
||||||
@@ -516,6 +519,9 @@ bool EditableMapObject::ValidatePhoneList(string const & phone)
|
|||||||
if (phone.empty())
|
if (phone.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(phone) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
auto constexpr kMaxNumberLen = 15;
|
auto constexpr kMaxNumberLen = 15;
|
||||||
auto constexpr kMinNumberLen = 5;
|
auto constexpr kMinNumberLen = 5;
|
||||||
|
|
||||||
@@ -556,6 +562,9 @@ bool EditableMapObject::ValidateEmail(string const & email)
|
|||||||
if (email.empty())
|
if (email.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(email) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (strings::IsASCIIString(email))
|
if (strings::IsASCIIString(email))
|
||||||
{
|
{
|
||||||
static auto const s_emailRegex = regex(R"([^@\s]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$)");
|
static auto const s_emailRegex = regex(R"([^@\s]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$)");
|
||||||
@@ -589,6 +598,9 @@ bool EditableMapObject::ValidateLevel(string const & level)
|
|||||||
if (level.empty())
|
if (level.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(level) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (level.front() == ';' || level.back() == ';' || level.find(";;") != std::string::npos)
|
if (level.front() == ';' || level.back() == ';' || level.find(";;") != std::string::npos)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -633,6 +645,9 @@ bool EditableMapObject::ValidateName(string const & name)
|
|||||||
if (name.empty())
|
if (name.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(name) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
static std::u32string_view constexpr excludedSymbols = U"^§><*=_±√•÷×¶";
|
static std::u32string_view constexpr excludedSymbols = U"^§><*=_±√•÷×¶";
|
||||||
|
|
||||||
using Iter = utf8::unchecked::iterator<string::const_iterator>;
|
using Iter = utf8::unchecked::iterator<string::const_iterator>;
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class EditableMapObject : public MapObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static uint8_t constexpr kMaximumLevelsEditableByUsers = 50;
|
static uint8_t constexpr kMaximumLevelsEditableByUsers = 50;
|
||||||
|
static int constexpr kMaximumOsmChars = 255;
|
||||||
|
|
||||||
bool IsNameEditable() const;
|
bool IsNameEditable() const;
|
||||||
bool IsAddressEditable() const;
|
bool IsAddressEditable() const;
|
||||||
|
|||||||
@@ -408,6 +408,10 @@ bool ValidateWebsite(string const & site)
|
|||||||
|
|
||||||
auto const startPos = GetProtocolNameLength(site);
|
auto const startPos = GetProtocolNameLength(site);
|
||||||
|
|
||||||
|
// check lengt and leave room for addition of 'http://'
|
||||||
|
if (strings::CountChar(site) > (IsProtocolSpecified(site) ? kMaximumOsmChars : kMaximumOsmChars - 7))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (startPos >= site.size())
|
if (startPos >= site.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -429,6 +433,9 @@ bool ValidateFacebookPage(string const & page)
|
|||||||
if (page.empty())
|
if (page.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(page) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Check if 'page' contains valid Facebook username or page name.
|
// Check if 'page' contains valid Facebook username or page name.
|
||||||
// * length >= 5
|
// * length >= 5
|
||||||
// * no forbidden symbols in the string
|
// * no forbidden symbols in the string
|
||||||
@@ -452,6 +459,9 @@ bool ValidateInstagramPage(string const & page)
|
|||||||
if (page.empty())
|
if (page.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(page) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Rules are defined here: https://blog.jstassen.com/2016/03/code-regex-for-instagram-username-and-hashtags/
|
// Rules are defined here: https://blog.jstassen.com/2016/03/code-regex-for-instagram-username-and-hashtags/
|
||||||
if (regex_match(page, s_instaRegex))
|
if (regex_match(page, s_instaRegex))
|
||||||
return true;
|
return true;
|
||||||
@@ -468,6 +478,9 @@ bool ValidateTwitterPage(string const & page)
|
|||||||
if (page.empty())
|
if (page.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(page) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!ValidateWebsite(page))
|
if (!ValidateWebsite(page))
|
||||||
return regex_match(page, s_twitterRegex); // Rules are defined here: https://stackoverflow.com/q/11361044
|
return regex_match(page, s_twitterRegex); // Rules are defined here: https://stackoverflow.com/q/11361044
|
||||||
|
|
||||||
@@ -480,6 +493,9 @@ bool ValidateVkPage(string const & page)
|
|||||||
if (page.empty())
|
if (page.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(page) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
{
|
{
|
||||||
// Check that page contains valid username. Rules took here: https://vk.com/faq18038
|
// Check that page contains valid username. Rules took here: https://vk.com/faq18038
|
||||||
// The page name must be between 5 and 32 characters.
|
// The page name must be between 5 and 32 characters.
|
||||||
@@ -513,6 +529,9 @@ bool ValidateLinePage(string const & page)
|
|||||||
if (page.empty())
|
if (page.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(page) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
{
|
{
|
||||||
// Check that linePage contains valid page name.
|
// Check that linePage contains valid page name.
|
||||||
// Rules are defined here: https://help.line.me/line/?contentId=10009904
|
// Rules are defined here: https://help.line.me/line/?contentId=10009904
|
||||||
@@ -536,6 +555,9 @@ bool ValidateFediversePage(string const & page)
|
|||||||
if (page.empty())
|
if (page.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(page) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Match @username@instance.name format
|
// Match @username@instance.name format
|
||||||
if (regex_match(page, s_fediverseRegex))
|
if (regex_match(page, s_fediverseRegex))
|
||||||
return true;
|
return true;
|
||||||
@@ -575,6 +597,9 @@ bool ValidateBlueskyPage(string const & page)
|
|||||||
if (page.empty())
|
if (page.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (strings::CountChar(page) > kMaximumOsmChars)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Match {@?}{user/domain.name} format
|
// Match {@?}{user/domain.name} format
|
||||||
if (regex_match(page, s_blueskyRegex))
|
if (regex_match(page, s_blueskyRegex))
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
namespace osm
|
namespace osm
|
||||||
{
|
{
|
||||||
|
static int constexpr kMaximumOsmChars = 255;
|
||||||
|
|
||||||
std::string ValidateAndFormat_website(std::string const & v);
|
std::string ValidateAndFormat_website(std::string const & v);
|
||||||
std::string ValidateAndFormat_facebook(std::string const & v);
|
std::string ValidateAndFormat_facebook(std::string const & v);
|
||||||
std::string ValidateAndFormat_instagram(std::string const & v);
|
std::string ValidateAndFormat_instagram(std::string const & v);
|
||||||
|
|||||||
Reference in New Issue
Block a user