mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +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 argparse
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path, PurePath, PureWindowsPath
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import importlib.metadata
|
import importlib.metadata
|
||||||
@ -225,7 +225,13 @@ def to_path(parser: argparse.ArgumentParser, name: str, *, replace_spaces: bool
|
|||||||
)
|
)
|
||||||
if len(name) <= 4 and name.upper() in forbidden:
|
if len(name) <= 4 and name.upper() in forbidden:
|
||||||
parser.error('invalid directory name given, use a different one')
|
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)
|
||||||
|
|
||||||
|
else:
|
||||||
name = name.translate(_translation_table)
|
name = name.translate(_translation_table)
|
||||||
if replace_spaces:
|
if replace_spaces:
|
||||||
name = name.replace(' ', '-')
|
name = name.replace(' ', '-')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user