From b53be04d0725a56c63c31afbcbf6a0a0b1026e59 Mon Sep 17 00:00:00 2001 From: Sujan Adhikari <109404840+Sujanadh@users.noreply.github.com> Date: Mon, 5 Aug 2024 22:31:54 +0545 Subject: [PATCH] refactor: check if place holders in custom tms url contains any space within (#281) * refactor: check if place holders in url contains any space within * docs: add comments to updates to basemapper TMS URL validation --------- Co-authored-by: Sam <78538841+spwoodcock@users.noreply.github.com> --- osm_fieldwork/basemapper.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/osm_fieldwork/basemapper.py b/osm_fieldwork/basemapper.py index e2466afd9..1ad60cca0 100755 --- a/osm_fieldwork/basemapper.py +++ b/osm_fieldwork/basemapper.py @@ -321,8 +321,16 @@ def customTMS(self, url: str, is_oam: bool = False, is_xy: bool = False): # FIXME handle other formats for custom TMS suffix = "jpg" - # Replace "{z}/{x}/{y}" with "%s" + # If placeholders present, validate they have no additional spaces + pattern = re.compile(r"\{\s*[xyz]+\s*\}") + if bool(pattern.search(url)): + msg = "Invalid TMS URL format. Please check the URL placeholders {z}/{x}/{y}." + log.error(msg) + raise ValueError(msg) + + # Remove "{z}/{x}/{y}" placeholders if they are present url = re.sub(r"/{[xyz]+\}", "", url) + # Append "%s" to the end of the URL to later add the tile path url = url + r"/%s" if is_oam: