mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
Update os.py
This commit is contained in:
parent
8887e727ca
commit
05868b474f
@ -104,16 +104,14 @@ class OsManager:
|
|||||||
if not path:
|
if not path:
|
||||||
return path
|
return path
|
||||||
|
|
||||||
# Decode unicode characters
|
# Decode unicode characters and perform basic sanitization
|
||||||
decoded = unidecode(path)
|
decoded = unidecode(path)
|
||||||
|
|
||||||
# Basic path sanitization
|
|
||||||
sanitized = sanitize_filepath(decoded)
|
sanitized = sanitize_filepath(decoded)
|
||||||
|
|
||||||
if self.system == 'windows':
|
if self.system == 'windows':
|
||||||
# Handle network paths (UNC or IP-based)
|
# Handle network paths (UNC or IP-based)
|
||||||
if path.startswith('\\\\') or path.startswith('//'):
|
if sanitized.startswith('\\\\') or sanitized.startswith('//'):
|
||||||
parts = path.replace('/', '\\').split('\\')
|
parts = sanitized.replace('/', '\\').split('\\')
|
||||||
# Keep server/IP and share name as is
|
# Keep server/IP and share name as is
|
||||||
sanitized_parts = parts[:4]
|
sanitized_parts = parts[:4]
|
||||||
# Sanitize remaining parts
|
# Sanitize remaining parts
|
||||||
@ -126,9 +124,9 @@ class OsManager:
|
|||||||
return '\\'.join(sanitized_parts)
|
return '\\'.join(sanitized_parts)
|
||||||
|
|
||||||
# Handle drive letters
|
# Handle drive letters
|
||||||
elif len(path) >= 2 and path[1] == ':':
|
elif len(sanitized) >= 2 and sanitized[1] == ':':
|
||||||
drive = path[:2]
|
drive = sanitized[:2]
|
||||||
rest = path[2:].lstrip('\\').lstrip('/')
|
rest = sanitized[2:].lstrip('\\').lstrip('/')
|
||||||
path_parts = [drive] + [
|
path_parts = [drive] + [
|
||||||
self.get_sanitize_file(part)
|
self.get_sanitize_file(part)
|
||||||
for part in rest.replace('/', '\\').split('\\')
|
for part in rest.replace('/', '\\').split('\\')
|
||||||
@ -138,12 +136,12 @@ class OsManager:
|
|||||||
|
|
||||||
# Regular path
|
# Regular path
|
||||||
else:
|
else:
|
||||||
parts = path.replace('/', '\\').split('\\')
|
parts = sanitized.replace('/', '\\').split('\\')
|
||||||
return '\\'.join(p for p in parts if p)
|
return '\\'.join(p for p in parts if p)
|
||||||
else:
|
else:
|
||||||
# Handle Unix-like paths (Linux and macOS)
|
# Handle Unix-like paths (Linux and macOS)
|
||||||
is_absolute = path.startswith('/')
|
is_absolute = sanitized.startswith('/')
|
||||||
parts = path.replace('\\', '/').split('/')
|
parts = sanitized.replace('\\', '/').split('/')
|
||||||
sanitized_parts = [
|
sanitized_parts = [
|
||||||
self.get_sanitize_file(part)
|
self.get_sanitize_file(part)
|
||||||
for part in parts
|
for part in parts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user