From 60badbf08f572ba4c00fa0a3aa55de2a9b2b2df3 Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 6 May 2026 21:32:25 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20zip=20filename=20decode=20=E2=80=94=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20UTF-8?= =?UTF-8?q?=20=D0=BE=D1=82=20macOS=20zip=20+=20cp866=20=D0=BE=D1=82=20Wind?= =?UTF-8?q?ows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Найдено в E2E на dev-сервере: macOS `zip` пишет UTF-8 имена БЕЗ флага UTF-8 (0x800), и Linux Python зфайл интерпретирует raw байты как cp437. Старый код жёстко конвертировал cp437→cp866 — это ломало UTF-8 имена. Фикс: пробуем оба codec'а (utf-8 первым — macOS, потом cp866 — Windows), берём результат без U+FFFD replacement chars. Co-Authored-By: Claude Opus 4.7 (1M context) --- gge_tools.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gge_tools.py b/gge_tools.py index bc42e68..ec3c4cb 100644 --- a/gge_tools.py +++ b/gge_tools.py @@ -16,13 +16,22 @@ from pathlib import Path def _decode_zip_name(info: zipfile.ZipInfo) -> str: """Python 3 zipfile авто-декодирует cp437 если флаг UTF-8 (0x800) не задан. - Для имён от Windows-архиваторов нужно re-encode→re-decode как cp866.""" + Реальные байты могут быть в UTF-8 (macOS `zip`) или cp866 (Windows-архиватор). + Пробуем оба, берём результат без replacement chars.""" if info.flag_bits & 0x800: return info.filename try: - return info.filename.encode('cp437').decode('cp866') - except UnicodeError: + raw = info.filename.encode('cp437') + except UnicodeEncodeError: return info.filename + for codec in ('utf-8', 'cp866'): + try: + decoded = raw.decode(codec) + if '�' not in decoded: + return decoded + except UnicodeDecodeError: + continue + return info.filename def extract_archive(zip_path: Path, target_dir: Path) -> dict: