Skip to content

Commit 7db3225

Browse files
gmileampcode-com
andcommitted
Fix path expansion for Slack cookies on macOS
Problem: Cookie file path contains unexpanded ~ tilde, causing 'unable to open database file' error when trying to access Slack cookies. String-based path operations don't handle ~ expansion. Fix: Use Path.home() from pathlib stdlib (https://docs.python.org/3/library/pathlib.html#pathlib.Path.home) which properly expands to the user's home directory. Amp-Thread-ID: https://ampcode.com/threads/T-019b4b52-707f-722f-bc8a-fc9a7853390d Co-authored-by: Amp <amp@ampcode.com>
1 parent fe0d689 commit 7db3225

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/pycookiecheat/chrome.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,18 @@ def get_macos_config(browser: BrowserType) -> dict:
121121
".get_macos_config"
122122
)
123123
raise ValueError(errmsg) from e
124-
cookie_file = "~" / app_support / cookies_suffix
124+
cookie_file = Path.home() / app_support / cookies_suffix
125125

126126
# Cookie location and keyring username in MacOS depends on whether the
127127
# application was installed from the App Store or direct download. To find
128128
# out, we simply assume it's direct download and fall back to App Store if
129129
# it's not there. Currently this distinction is only known for Slack, so
130130
# that is the only case handled here.
131131
isAppStore = False
132-
if browser is BrowserType.SLACK and not cookie_file.expanduser().exists():
132+
if browser is BrowserType.SLACK and not cookie_file.exists():
133133
isAppStore = True
134134
cookie_file = (
135-
"~/Library/Containers/com.tinyspeck.slackmacgap/Data"
135+
Path.home() / "Library/Containers/com.tinyspeck.slackmacgap/Data"
136136
/ app_support / cookies_suffix
137137
)
138138

0 commit comments

Comments
 (0)