Skip to content

Commit 43b81ae

Browse files
committed
font-patcher: Allow absolute paths on Windows
[why] On Windows an absolute path can start with the drive letter followed by a colon. When we sanitize the pathname the colon is replaced by an underscore. [how] Add special handling on Windows. Signed-off-by: Fini Jastrow <[email protected]>
1 parent a880ec5 commit 43b81ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

font-patcher

+5-1
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ def sanitize_filename(filename, allow_dirs = False):
18451845
""" Enforces to not use forbidden characters in a filename/path. """
18461846
if filename == '.' and not allow_dirs:
18471847
return '_'
1848+
restore_colon = sys.platform == 'win32' and re.match('[a-z]:', filename, re.I)
18481849
trans = filename.maketrans('<>:"|?*', '_______')
18491850
for i in range(0x00, 0x20):
18501851
trans[i] = ord('_')
@@ -1853,7 +1854,10 @@ def sanitize_filename(filename, allow_dirs = False):
18531854
trans[ord('\\')] = ord('_')
18541855
else:
18551856
trans[ord('\\')] = ord('/') # We use Posix paths
1856-
return filename.translate(trans)
1857+
new_filename = filename.translate(trans)
1858+
if restore_colon:
1859+
new_filename[1] = ':'
1860+
return new_filename
18571861

18581862
def get_multiglyph_boundingBox(glyphs, destGlyph = None):
18591863
""" Returns dict of the dimensions of multiple glyphs combined(, as if they are copied into destGlyph) """

0 commit comments

Comments
 (0)