Skip to content

Commit 116d392

Browse files
committed
owfile: Parse and encode url
1 parent 34ce9d5 commit 116d392

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Orange/widgets/data/owfile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ def _get_reader(self) -> FileFormat:
470470
return reader
471471
else:
472472
url = self.url_combo.currentText().strip()
473+
# tolerant parse, also prevent parsing as local file
474+
parsed = QUrl.fromUserInput(url, os.devnull)
475+
if parsed.isValid():
476+
url = bytes(parsed.toEncoded()).decode("ascii")
473477
return UrlReader(url)
474478

475479
def _update_sheet_combo(self):

Orange/widgets/data/tests/test_owfile.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,21 @@ def test_url_no_scheme(self):
577577

578578
mock_urlreader.assert_called_once_with('http://' + url)
579579

580+
def test_url_encode(self):
581+
def test(text, expected):
582+
mock_urlreader = Mock()
583+
with patch('Orange.widgets.data.owfile.UrlReader', mock_urlreader):
584+
self.widget.url_combo.insertItem(0, text)
585+
self.widget.url_combo.setCurrentIndex(0)
586+
self.widget.url_combo.activated.emit(0)
587+
mock_urlreader.assert_called_once_with(expected)
588+
589+
test("https://example.com/space space#f=f", "https://example.com/space%20space#f=f")
590+
test("https://example.com/space%20space#f=f", "https://example.com/space%20space#f=f")
591+
test("https://š.si/š#f=1", "https://xn--pga.si/%C5%A1#f=1")
592+
test("https://xn--pga.si/%C5%A1#f=1", "https://xn--pga.si/%C5%A1#f=1")
593+
test("https://example.com/a?q=1#f=1", "https://example.com/a?q=1#f=1")
594+
580595
def test_adds_origin(self):
581596
self.open_dataset("origin1/images")
582597
data1 = self.get_output(self.widget.Outputs.data)

0 commit comments

Comments
 (0)