v0.0.67: фикс кириллических имён из ZIP (UTF-8 без флага -> мусор CP866) — строгая UTF-8 проверка в decodeZipName
Deploy drhider / validate (push) Canceled after 0s
Deploy drhider / validate (push) Canceled after 0s
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ if _sys_path_root not in sys.path:
|
|||||||
sys.path.insert(0, _sys_path_root)
|
sys.path.insert(0, _sys_path_root)
|
||||||
|
|
||||||
# Версия приложения (меняется при изменениях)
|
# Версия приложения (меняется при изменениях)
|
||||||
VERSION = "0.0.66"
|
VERSION = "0.0.67"
|
||||||
|
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging():
|
||||||
|
|||||||
@@ -405,6 +405,14 @@ function dosToMs(date, time) {
|
|||||||
|
|
||||||
function decodeZipName(bytes, isUtf8) {
|
function decodeZipName(bytes, isUtf8) {
|
||||||
if (isUtf8) return new TextDecoder('utf-8').decode(bytes);
|
if (isUtf8) return new TextDecoder('utf-8').decode(bytes);
|
||||||
|
// Многие архиваторы пишут имя в UTF-8, но НЕ выставляют UTF-8-флаг (bit 11).
|
||||||
|
// Сначала строго пробуем UTF-8: если байты — валидный UTF-8 с кириллицей/текстом,
|
||||||
|
// берём их как есть (иначе декодирование CP437→CP866 превратит их в «╨╣…»-мусор).
|
||||||
|
try {
|
||||||
|
const s = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
||||||
|
// Кириллица — точно UTF-8; либо чистый печатаемый текст без управляющих символов.
|
||||||
|
if (/[\u0400-\u04FF]/.test(s) || !/[^\u0020-\u007e]/.test(s)) return s;
|
||||||
|
} catch (e) { /* не UTF-8 — legacy (CP437/CP866) */ }
|
||||||
let name;
|
let name;
|
||||||
try { name = new TextDecoder('ibm437').decode(bytes); }
|
try { name = new TextDecoder('ibm437').decode(bytes); }
|
||||||
catch (e) { name = new TextDecoder('utf-8').decode(bytes); }
|
catch (e) { name = new TextDecoder('utf-8').decode(bytes); }
|
||||||
|
|||||||
Reference in New Issue
Block a user