fix: UTF-8 BOM in RDP bundle zip for Russian Windows PowerShell (0.20.16)
This commit is contained in:
@@ -10,6 +10,8 @@ from pathlib import Path
|
||||
from threading import Lock
|
||||
|
||||
TTL_SECONDS = 600
|
||||
_UTF8_BOM = b"\xef\xbb\xbf"
|
||||
_BOM_SUFFIXES = {".ps1", ".txt"}
|
||||
|
||||
_lock = Lock()
|
||||
_entries: dict[str, tuple[bytes, float]] = {}
|
||||
@@ -21,13 +23,23 @@ def _prune_expired(now: float) -> None:
|
||||
_entries.pop(token, None)
|
||||
|
||||
|
||||
def _bundle_file_bytes(path: Path) -> bytes:
|
||||
data = path.read_bytes()
|
||||
if path.suffix.lower() in _BOM_SUFFIXES and not data.startswith(_UTF8_BOM):
|
||||
return _UTF8_BOM + data
|
||||
return data
|
||||
|
||||
|
||||
def build_rdp_bundle_zip(repo_dir: Path, filenames: tuple[str, ...]) -> bytes:
|
||||
buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED) as archive:
|
||||
for name in filenames:
|
||||
path = repo_dir / name
|
||||
if path.is_file():
|
||||
archive.write(path, name)
|
||||
info = zipfile.ZipInfo(name)
|
||||
info.compress_type = zipfile.ZIP_DEFLATED
|
||||
info.flag_bits |= 0x800
|
||||
archive.writestr(info, _bundle_file_bytes(path))
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user