Files
subwatcher/services/core/test/encoding.test.ts
szbk 4606970577 feat: clamav tarama sistemi ve hata yönetimi iyileştirmeleri ekle
ClamAV entegrasyonu ile indirilen altyazı dosyalarının otomatik virüs taraması
eklendi. Pipeline tabanlı hata yönetimi sistemi ile hatalar kategorize edilip
daha iyi işleniyor. Türkcealtyazi sağlayıcısı TV dizileri için sezon/bölüm
bazlı eşleştirme ve paket indirme desteği kazandı. Dosya izleyicide olay
çiftleme (deduplication) mekanizması eklendi. Metin kodlaması normalizasyonu
Türkçe karakterler için geliştirildi.
2026-02-16 13:44:42 +03:00

34 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import iconv from 'iconv-lite';
import { normalizeSubtitleBuffer } from '../src/utils/file.js';
describe('normalizeSubtitleBuffer', () => {
const sample = '1\r\n00:00:01,000 --> 00:00:02,000\r\nÇığ ÖşÜ ıİ\r\n';
it('keeps valid utf8 Turkish characters intact', () => {
const buf = Buffer.from(sample, 'utf8');
const out = normalizeSubtitleBuffer(buf);
expect(out).toBe('1\n00:00:01,000 --> 00:00:02,000\nÇığ ÖşÜ ıİ\n');
});
it('decodes windows-1254 Turkish text correctly', () => {
const buf = iconv.encode(sample, 'windows-1254');
const out = normalizeSubtitleBuffer(buf);
expect(out).toBe('1\n00:00:01,000 --> 00:00:02,000\nÇığ ÖşÜ ıİ\n');
});
it('decodes utf16-le BOM correctly', () => {
const buf = iconv.encode(sample, 'utf16-le');
const withBom = Buffer.concat([Buffer.from([0xff, 0xfe]), buf]);
const out = normalizeSubtitleBuffer(withBom);
expect(out).toBe('1\n00:00:01,000 --> 00:00:02,000\nÇığ ÖşÜ ıİ\n');
});
it('repairs mojibake form with \u00fd/\u00fe/\u00f0 Turkish corruption', () => {
const mojibake = '1\r\n00:00:01,000 --> 00:00:02,000\r\nKýz þöyle dedi: aðýr bir iþ.\r\n';
const buf = Buffer.from(mojibake, 'utf8');
const out = normalizeSubtitleBuffer(buf);
expect(out).toContain('Kız şöyle dedi: ağır bir iş.');
});
});