Skip to content

Python tool for converting files and office documents to Markdown.

fix: match ExifTool directories case-insensitively on Windows (#2837)

Yasser Ameured178952a667
diff --git a/packages/markitdown/src/markitdown/_markitdown.py b/packages/markitdown/src/markitdown/_markitdown.py
index 45cef7fb..53ba8b1a 100644
--- a/packages/markitdown/src/markitdown/_markitdown.py
+++ b/packages/markitdown/src/markitdown/_markitdown.py
@@ -207,8 +207,10 @@ class MarkItDown:
candidate = shutil.which("exiftool")
if candidate:
candidate = os.path.abspath(candidate)
+ # normcase: Windows directories match in any letter case
+ candidate_dir = os.path.normcase(os.path.dirname(candidate))
if any(
- d == os.path.dirname(candidate)
+ os.path.normcase(d) == candidate_dir
for d in [
"/usr/bin",
"/usr/local/bin",
diff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.py
index e9cba9ca..103d912f 100644
--- a/packages/markitdown/tests/test_module_misc.py
+++ b/packages/markitdown/tests/test_module_misc.py
@@ -707,6 +707,58 @@ def test_windows_local_drive_uri(authority: str, uri_path: str, expected: str) -
assert path == expected
+# ExifTool discovery
+
+
+def _discovered_exiftool(monkeypatch: pytest.MonkeyPatch, found: str):
+ monkeypatch.delenv("EXIFTOOL_PATH", raising=False)
+ monkeypatch.setattr(
+ "markitdown._markitdown.shutil.which",
+ lambda name: found if name == "exiftool" else None,
+ )
+ return MarkItDown()._exiftool_path
+
+
[email protected](os.name != "nt", reason="Windows paths are case-insensitive")
+ "found",
+ [
+ r"C:\Windows\System32\exiftool.exe",
+ # The default Windows PATH spells System32 like this.
+ r"C:\WINDOWS\system32\exiftool.exe",
+ r"c:\program files\exiftool.exe",
+ "C:/Program Files (x86)/exiftool.exe",
+ ],
+)
+def test_exiftool_found_in_windows_directory_of_any_case(
+ monkeypatch: pytest.MonkeyPatch, found: str
+) -> None:
+ assert _discovered_exiftool(monkeypatch, found) == os.path.abspath(found)
+
+
+ "found",
+ [
+ r"C:\Windows\Temp\exiftool.exe",
+ r"C:\WINDOWS\system32\tools\exiftool.exe",
+ "/home/user/bin/exiftool",
+ "/usr/bin/tools/exiftool",
+ ],
+)
+def test_exiftool_outside_trusted_directories_is_ignored(
+ monkeypatch: pytest.MonkeyPatch, found: str
+) -> None:
+ assert _discovered_exiftool(monkeypatch, found) is None
+
+
[email protected](os.name == "nt", reason="POSIX paths are case-sensitive")
+def test_exiftool_posix_directory_match_is_exact(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ assert _discovered_exiftool(monkeypatch, "/usr/bin/exiftool") == "/usr/bin/exiftool"
+ assert _discovered_exiftool(monkeypatch, "/USR/BIN/exiftool") is None
+
+
# Charset sampling