Skip to content

Commit 6f25bda

Browse files
authored
Merge pull request #5412 from VesnaT/url_reader_special_chars
[FIX] UrlReader: Support urls with special characters
2 parents ce6222e + 62a7605 commit 6f25bda

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Orange/data/io.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
from os import path, remove
1515
from tempfile import NamedTemporaryFile
16-
from urllib.parse import urlparse, urlsplit, urlunsplit, unquote as urlunquote
16+
from urllib.parse import urlparse, urlsplit, urlunsplit, \
17+
unquote as urlunquote, quote
1718
from urllib.request import urlopen, Request
1819
from pathlib import Path
1920

@@ -405,6 +406,7 @@ def __init__(self, filename):
405406
filename = filename.strip()
406407
if not urlparse(filename).scheme:
407408
filename = 'http://' + filename
409+
filename = quote(filename, safe="/:")
408410
super().__init__(filename)
409411

410412
@staticmethod

Orange/tests/test_url_reader.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ def test_zipped(self):
1717
"http://datasets.biolab.si/core/philadelphia-crime.csv.xz"
1818
).read()
1919
self.assertEqual(9666, len(data))
20+
21+
def test_special_characters(self):
22+
# TO-DO - replace this file with a more appropriate one (e.g. .csv)
23+
# and change the assertion accordingly
24+
path = "http://file.biolab.si/text-semantics/data/elektrotehniski-" \
25+
"vestnik-clanki/detektiranje-utrdb-v-šahu-.txt"
26+
self.assertRaises(OSError, UrlReader(path).read)
27+
28+
29+
if __name__ == "__main__":
30+
unittest.main()

0 commit comments

Comments
 (0)