diff --git a/memsync/harvest.py b/memsync/harvest.py index 975773d..493bb5a 100644 --- a/memsync/harvest.py +++ b/memsync/harvest.py @@ -26,8 +26,8 @@ def cwd_to_project_key(cwd: Path) -> str: # Drive letter colon becomes a dash; backslashes become dashes # e.g. C:\Users\Ian\foo → C--Users-Ian-foo raw = str(cwd.resolve()) - return raw.replace(":", "-").replace("\\", "-") - return str(cwd.resolve()).replace("/", "-") + return raw.replace(":", "-").replace("\\", "-").replace(" ", "-") + return str(cwd.resolve()).replace("/", "-").replace(" ", "-") def find_project_dir( diff --git a/tests/test_harvest.py b/tests/test_harvest.py index 9a2aef2..e1d345d 100644 --- a/tests/test_harvest.py +++ b/tests/test_harvest.py @@ -60,6 +60,20 @@ def test_nested_path(self): p = Path("/Users/ian/Documents/GitHub/memsync") assert cwd_to_project_key(p) == "-Users-ian-Documents-GitHub-memsync" + def test_spaces_in_path_unix(self): + if platform.system() == "Windows": + pytest.skip("Unix path test") + p = Path("/Users/ian/Documents/Untitled Gods Book") + assert cwd_to_project_key(p) == "-Users-ian-Documents-Untitled-Gods-Book" + + def test_spaces_in_path_windows(self, monkeypatch): + if platform.system() != "Windows": + pytest.skip("Windows path test") + p = Path(r"C:\Users\ianfe\OneDrive\Documents\Untitled Gods Book") + key = cwd_to_project_key(p) + assert "Untitled-Gods-Book" in key + assert " " not in key + # --------------------------------------------------------------------------- # find_project_dir