From baf10ca888ed9aa17c9da846492c9ce8ed5a46e8 Mon Sep 17 00:00:00 2001
From: olivier <olivier.winter@hotmail.fr>
Date: Tue, 6 Jul 2021 21:40:19 +0100
Subject: [PATCH] webclient download file: encode special characters in file
 name for URL

---
 one/webclient.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/one/webclient.py b/one/webclient.py
index 8037d06..6b8a4fd 100644
--- a/one/webclient.py
+++ b/one/webclient.py
@@ -34,6 +34,7 @@ import os
 import re
 import functools
 import urllib.request
+import urllib.parse
 from urllib.error import HTTPError
 from collections.abc import Mapping
 from typing import Optional
@@ -278,6 +279,10 @@ def http_download_file(full_link_to_file, chunks=None, *, clobber=False, silent=
     """
     if not full_link_to_file:
         return ''
+    # makes sure special characters get encoded (# in file names for example)
+    surl = urllib.parse.urlsplit(full_link_to_file, allow_fragments=False)._asdict()
+    surl['path'] = urllib.parse.quote(surl['path'])
+    full_link_to_file = urllib.parse.urlunsplit(urllib.parse.SplitResult(**surl))
 
     # default cache directory is the home dir
     if not cache_dir:
@@ -764,7 +769,7 @@ class AlyxClient(metaclass=UniqueSingletons):
                         query = ','.join(kwargs[k])
                     else:
                         query = str(kwargs[k])
-                    url = url + f"&{k}=" + query
+                    url = url + f"&{k}=" + urllib.parse.quote(query)
             return self.get('/' + url, **cache_args)
         if action == 'read':
             assert (endpoint_scheme[action]['action'] == 'get')
-- 
GitLab