1010logger = get_logger (__name__ )
1111
1212
13+ def _quote_url_if_comma (url ):
14+ """Wrap url in double quotes if it contains a comma, to prevent CSV parsing errors."""
15+ if url and "," in url :
16+ return f'"{ url } "'
17+ return url
18+
19+
1320def get_request (url , verify_ssl = True ):
1421 # log["ssl-verify"] = verify_ssl
1522 log = {"status" : "" , "message" : "" }
@@ -315,14 +322,16 @@ def validate_endpoint(url, config_dir, plugin, start_date=None):
315322 ]
316323 )
317324
325+ safe_url = _quote_url_if_comma (url )
326+
318327 endpoint_exists = False
319328 existing_entry = None
320329
321330 try :
322331 with open (endpoint_csv_path , "r" , encoding = "utf-8" ) as f :
323332 reader = csv .DictReader (f )
324333 for row in reader :
325- if row .get ("endpoint-url" , "" ).strip () == url .strip ():
334+ if row .get ("endpoint-url" , "" ).strip () == safe_url .strip ():
326335 endpoint_exists = True
327336 existing_entry = {
328337 "endpoint" : row .get ("endpoint" , "" ),
@@ -350,7 +359,7 @@ def validate_endpoint(url, config_dir, plugin, start_date=None):
350359
351360 endpoint_key , new_endpoint_row = append_endpoint (
352361 endpoint_csv_path = endpoint_csv_path ,
353- endpoint_url = url ,
362+ endpoint_url = safe_url ,
354363 entry_date = entry_date ,
355364 start_date = start_date ,
356365 end_date = "" ,
@@ -387,6 +396,8 @@ def validate_source(
387396 if not documentation_url :
388397 logger .warning ("No documentation URL provided" )
389398
399+ safe_documentation_url = _quote_url_if_comma (documentation_url ) if documentation_url else ""
400+
390401 if not start_date :
391402 start_date = datetime .now ().strftime ("%Y-%m-%d" )
392403 entry_date = datetime .now ().isoformat ()
@@ -397,7 +408,7 @@ def validate_source(
397408 organisation = organisation ,
398409 endpoint_key = endpoint_key ,
399410 attribution = "" ,
400- documentation_url = documentation_url or "" ,
411+ documentation_url = safe_documentation_url ,
401412 licence = licence or "" ,
402413 pipelines = dataset ,
403414 entry_date = entry_date ,
0 commit comments