Skip to content

Commit 98fe7c0

Browse files
committed
Check if dirname exists
We only want to path normalize a string (and replace backslashes with forward slashes if on Windows) if it's actually a path. But checking if there's a path with that name doesn't work if the path is a substring of an actual path. Additionally check whether the dirname points to something on the file system. If it does, it's likely meant to be interpreted as a path.
1 parent b22e4d2 commit 98fe7c0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

utils/PathSanitizingFileCheck

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import sys
2323
# this normalizes Windows paths to use backslashes, we have to replace them
2424
# back to forward slashes.
2525
def normalize_if_path(s):
26-
if not os.path.exists(s):
26+
# Check dirname for cases like a file named `%t.out.txt`
27+
# There won't be a `%t` path, but we still want to match this path substring.
28+
if not os.path.exists(s) and not os.path.exists(os.path.dirname(s)):
2729
return s
2830
if platform.system() == "Windows":
2931
return os.path.abspath(s).replace('\\', '/')

0 commit comments

Comments
 (0)