uploadNames.test.ts 740 B

1234567891011121314151617
  1. // @vitest-environment node
  2. import { expect, it } from 'vitest'
  3. import { normalizeUploadName } from '../../src/shared/uploadNames'
  4. it.each([
  5. '人工智能合同综合质量评估系统V2.0-信息采集表-待确认.docx',
  6. 'café-附件-📄.txt',
  7. ])('recovers a legacy Latin-1 decoding of %s exactly once', name => {
  8. const corrupted = Buffer.from(name, 'utf8').toString('latin1')
  9. expect(normalizeUploadName(corrupted)).toBe(name)
  10. expect(normalizeUploadName(normalizeUploadName(corrupted))).toBe(name)
  11. })
  12. it.each(['report.txt', '中文附件.docx', 'café.txt', 'ÿ.txt', '坏数据-äº.txt', 'äº.txt'])
  13. ('preserves names that cannot be safely recovered: %s', name => {
  14. expect(normalizeUploadName(name)).toBe(name)
  15. })