From: Sarah Hoffmann Date: Tue, 5 Sep 2023 09:26:47 +0000 (+0200) Subject: avoid interpreting integral numbers as coordinates X-Git-Tag: v4.3.0~6^2~2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/18b2a4c2048149128e45698d0a15dfdc9a696680 avoid interpreting integral numbers as coordinates There are addresses of type '123 W 345 N, Reigh', where 'W 345 N' is the actual name of the street. --- diff --git a/nominatim/api/v1/helpers.py b/nominatim/api/v1/helpers.py index 325e5bc6..6a646e4f 100644 --- a/nominatim/api/v1/helpers.py +++ b/nominatim/api/v1/helpers.py @@ -136,10 +136,10 @@ def _deg(axis:str) -> str: return f"(?P<{axis}_deg>\\d+\\.\\d+)°?" def _deg_min(axis: str) -> str: - return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>[\\d.]+)?[′']*" + return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>[\\d.]+)[′']*" def _deg_min_sec(axis: str) -> str: - return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>\\d+)[′'\\s]+(?P<{axis}_sec>[\\d.]+)?[\"″]*" + return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>\\d+)[′'\\s]+(?P<{axis}_sec>[\\d.]+)[\"″]*" COORD_REGEX = [re.compile(r'(?:(?P
.*?)\s+)??' + r + r'(?:\s+(?P.*))?') for r in (
     r"(?P[NS])\s*" + _deg('lat') + r"[\s,]+" + r"(?P[EW])\s*" + _deg('lon'),
diff --git a/test/python/api/test_helpers_v1.py b/test/python/api/test_helpers_v1.py
index 45f538de..e4862b0d 100644
--- a/test/python/api/test_helpers_v1.py
+++ b/test/python/api/test_helpers_v1.py
@@ -11,7 +11,11 @@ import pytest
 
 import nominatim.api.v1.helpers as helper
 
-@pytest.mark.parametrize('inp', ['', 'abc', '12 23', 'abc -78.90, 12.456 def'])
+@pytest.mark.parametrize('inp', ['',
+                                 'abc',
+                                 '12 23',
+                                 'abc -78.90, 12.456 def',
+                                 '40 N 60 W'])
 def test_extract_coords_no_coords(inp):
     query, x, y = helper.extract_coords_from_query(inp)