From 54fffdfb1bee94a6c6617f996061cef1c4fc946b Mon Sep 17 00:00:00 2001 From: vng Date: Fri, 17 May 2013 21:50:21 +0300 Subject: [PATCH] Do not parse whole string in "geo" url and Validate it. --- map/geourl_process.cpp | 26 ++++++++++++++++++++++++-- map/geourl_process.hpp | 10 ++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/map/geourl_process.cpp b/map/geourl_process.cpp index 9d628534d0..55d488400c 100644 --- a/map/geourl_process.cpp +++ b/map/geourl_process.cpp @@ -8,9 +8,14 @@ namespace url_scheme { + bool Info::IsValid() const + { + return (MercatorBounds::ValidLat(m_lat) && MercatorBounds::ValidLon(m_lon)); + } + void Info::Reset() { - m_lat = m_lon = EmptyValue(); + m_lat = m_lon = -1000.0; m_zoom = scales::GetUpperScale(); } @@ -91,6 +96,14 @@ namespace url_scheme if (!CheckKeyword(token)) { ToDouble(token, m_info.m_zoom); + + // validate zoom bounds + if (m_info.m_zoom < 0.0) + m_info.m_zoom = 0.0; + int const upperScale = scales::GetUpperScale(); + if (m_info.m_zoom > upperScale) + m_info.m_zoom = upperScale; + m_mode = FINISH; } break; @@ -99,10 +112,19 @@ namespace url_scheme break; } } + + bool IsEnd() const { return m_mode == FINISH; } }; void ParseGeoURL(string const & s, Info & info) { - strings::Tokenize(s, ":/?&=,", DoGeoParse(info)); + DoGeoParse parser(info); + strings::SimpleTokenizer iter(s, ":/?&=,"); + + while (iter && !parser.IsEnd()) + { + parser(*iter); + ++iter; + } } } diff --git a/map/geourl_process.hpp b/map/geourl_process.hpp index 43bf271b27..7a728eff58 100644 --- a/map/geourl_process.hpp +++ b/map/geourl_process.hpp @@ -11,13 +11,7 @@ namespace url_scheme { double m_lat, m_lon, m_zoom; - static double EmptyValue() { return -1000.0; } - - bool IsValid() const - { - return (m_lat != EmptyValue() && m_lon != EmptyValue()); - } - + bool IsValid() const; void Reset(); Info() @@ -26,7 +20,7 @@ namespace url_scheme } m2::RectD GetViewport() const; - // @return lat and lon in Mercator projection + /// @return lat and lon in Mercator projection m2::PointD GetMercatorPoint() const; };