mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-18 15:06:07 +00:00
Fix path sanitation for absolute Windows paths
When using an absolute Windows path (e.g. `C:\Users\USER\Documents\`) for the `newbot` command the translation table replaced the valid `:` character in the drive causing it to create the directory at the wrong place. Fixes #10096
This commit is contained in:
parent
42e4a87374
commit
52967ec103
@ -28,7 +28,7 @@ from typing import Optional, Tuple, Dict
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from pathlib import Path, PurePath, PureWindowsPath
|
||||
|
||||
import discord
|
||||
import importlib.metadata
|
||||
@ -225,8 +225,14 @@ def to_path(parser: argparse.ArgumentParser, name: str, *, replace_spaces: bool
|
||||
)
|
||||
if len(name) <= 4 and name.upper() in forbidden:
|
||||
parser.error('invalid directory name given, use a different one')
|
||||
path = PurePath(name)
|
||||
if isinstance(path, PureWindowsPath) and path.drive:
|
||||
drive, rest = path.parts[0], path.parts[1:]
|
||||
transformed = tuple(map(lambda p: p.translate(_translation_table), rest))
|
||||
name = drive + '\\'.join(transformed)
|
||||
|
||||
name = name.translate(_translation_table)
|
||||
else:
|
||||
name = name.translate(_translation_table)
|
||||
if replace_spaces:
|
||||
name = name.replace(' ', '-')
|
||||
return Path(name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user