Try decoding geo URL coordinates before giving up on parsing

Signed-off-by: Nic Pottier <nicpottier@gmail.com>
This commit is contained in:
Nic Pottier 2024-08-16 09:32:36 -07:00 committed by Alexander Borsuk
parent 4d07de2b85
commit b39c0e0529
2 changed files with 12 additions and 2 deletions

View file

@ -96,6 +96,12 @@ UNIT_TEST(GeoUrl_Geo)
TEST_ALMOST_EQUAL_ABS(info.m_lat, 53.666, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, 0.0, kEps, ());
// URL Encoded comma (%2C) as delimiter
TEST(parser.Parse("geo:-18.9151863%2C-48.28712359999999?q=-18.9151863%2C-48.28712359999999", info), ());
TEST(info.IsLatLonValid(), ());
TEST_ALMOST_EQUAL_ABS(info.m_lat, -18.9151863, kEps, ());
TEST_ALMOST_EQUAL_ABS(info.m_lon, -48.28712359999999, kEps, ());
// Invalid coordinates.
TEST(!parser.Parse("geo:0,0garbage", info), ());
TEST(!parser.Parse("geo:garbage0,0", info), ());

View file

@ -205,8 +205,12 @@ bool GeoParser::Parse(std::string const & raw, GeoURLInfo & info) const
std::smatch m;
if (!std::regex_match(coordinates, m, m_latlonRe) || m.size() < 3)
{
LOG(LWARNING, ("Missing coordinates in", raw));
return false;
// no match? try URL decoding before giving up
coordinates = url::UrlDecode(coordinates);
if (!std::regex_match(coordinates, m, m_latlonRe) || m.size() < 3){
LOG(LWARNING, ("Missing coordinates in", raw));
return false;
}
}
double lat, lon;