Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/click/_termui_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ def _unquote_file(url: str) -> str:
elif WIN:
if locate:
url = _unquote_file(url)
args = ["explorer", f"/select,{url}"]
url = url.replace('"', '""')
args = ["explorer", f'/select,"{url}"']
try:
return subprocess.call(args)
except OSError:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_termui.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,20 @@ def test_editor_nonexistent_exception():
Editor(editor="nonexistent").edit_files(["f.txt"])


def test_launch_windows_locate_quotes_path_with_spaces(monkeypatch):
monkeypatch.setattr(click._termui_impl.sys, "platform", "win32")
monkeypatch.setattr(click._termui_impl, "WIN", True)
monkeypatch.setattr(click._termui_impl, "CYGWIN", False)

with patch("subprocess.call", return_value=0) as mock_call:
rv = click._termui_impl.open_url(r"C:\Users\Public\click demo", locate=True)

assert rv == 0
mock_call.assert_called_once_with(
["explorer", r'/select,"C:\Users\Public\click demo"']
)


@pytest.mark.parametrize(
("pager_env", "expected_parts"),
[
Expand Down
Loading