From 426d38dd7946171fb33b8567db91bf2cd9a158e3 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Mon, 8 Jun 2026 11:26:58 +0200 Subject: [PATCH] strip replaced phrases --- src/nominatim_api/query_preprocessing/regex_replace.py | 4 ++-- test/python/api/query_processing/test_regex_replace.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nominatim_api/query_preprocessing/regex_replace.py b/src/nominatim_api/query_preprocessing/regex_replace.py index 2433c917..ec7e8828 100644 --- a/src/nominatim_api/query_preprocessing/regex_replace.py +++ b/src/nominatim_api/query_preprocessing/regex_replace.py @@ -37,7 +37,7 @@ class _GenericPreprocessing: def split_phrase(self, phrase: Phrase) -> Phrase: """This function performs replacements on the given text using regex patterns.""" for item in self.compiled_patterns: - phrase.text = item[0].sub(item[1], phrase.text) + phrase.text = item[0].sub(item[1], phrase.text).strip() return phrase @@ -46,7 +46,7 @@ class _GenericPreprocessing: Return the final Phrase list. Returns an empty list if there is nothing left after split_phrase. """ - result = [p for p in map(self.split_phrase, phrases) if p.text.strip()] + result = [p for p in map(self.split_phrase, phrases) if p.text] return result diff --git a/test/python/api/query_processing/test_regex_replace.py b/test/python/api/query_processing/test_regex_replace.py index 26d32eb6..bb8caf87 100644 --- a/test/python/api/query_processing/test_regex_replace.py +++ b/test/python/api/query_processing/test_regex_replace.py @@ -36,9 +36,9 @@ def run_preprocessor_on(query): (['http://osm.org'], []), (['https://www.openstreetmap.org/user/abc'], []), (['https://tile.openstreetmap.org/12/2048/2048.png'], []), - (['Check the map at https://www.openstreetmap.org'], ['Check the map at ']), + (['Check the map at https://www.openstreetmap.org'], ['Check the map at']), (['Use 203.0.113.255 for routing'], ['Use for routing']), - (['Find maps at https://osm.org and http://openstreetmap.org'], ['Find maps at and ']), + (['Find maps at https://osm.org and http://openstreetmap.org'], ['Find maps at and']), (['203.0.113.255', 'Some Address'], ['Some Address']), (['https://osm.org', 'Another Place'], ['Another Place']), ]) -- 2.47.3