A folder-picked Fortnox export failed 50 of 50 attaches with UNDERLAG_REF_MISMATCH although the preview had matched every file. The preview is built from File.name, a bare filename by spec, while the attach route read the multipart filename, which Chrome fills with the folder-relative path for folder selections (2026/06/Leverantorsfakturor/A166_x.pdf). The guard that requires a file to land where the preview said compared the previewed basename with a path the parser cannot read, and refused. The route now reduces the multipart filename to its basename once, at the boundary, before the resolver check and before archiving, so the archived file_name is the name the user reviewed rather than a path. The parser keeps its no-directory-stripping rule: the manual-reference box shares it, and a typed 2024/01/31 there is a date, not voucher 31. Both separators are stripped; nothing else is normalized. Claude-Session: https://claude.ai/code/session_014uwXchJvF5YMgz8vRfuxLe Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { uploadedFileBaseName } from '@/lib/documents/upload-file-name'
|
|
|
|
describe('uploadedFileBaseName', () => {
|
|
it('returns a bare filename unchanged', () => {
|
|
expect(uploadedFileBaseName('A31_8c2db060.pdf')).toBe('A31_8c2db060.pdf')
|
|
})
|
|
|
|
it('strips the folder-relative path Chrome writes for a folder selection', () => {
|
|
// Real shape from a Fortnox export: <year>/<month>/<type>/<file>.
|
|
expect(
|
|
uploadedFileBaseName(
|
|
'2026/06/Leverantörsfakturor/A166_90493_62864442_Hetzner_2026-05-13_089000921156.pdf',
|
|
),
|
|
).toBe('A166_90493_62864442_Hetzner_2026-05-13_089000921156.pdf')
|
|
})
|
|
|
|
it('strips Windows-style separators too', () => {
|
|
expect(uploadedFileBaseName('2026\\01\\Verifikationer\\A17_kvitto.pdf')).toBe('A17_kvitto.pdf')
|
|
})
|
|
|
|
it('keeps dots, spaces and Swedish characters inside the name', () => {
|
|
expect(uploadedFileBaseName('2026/01/A17_Förhandsavi 2026 Årsavgift 734 314 922.pdf')).toBe(
|
|
'A17_Förhandsavi 2026 Årsavgift 734 314 922.pdf',
|
|
)
|
|
expect(uploadedFileBaseName('A31.kvitto.v2.pdf')).toBe('A31.kvitto.v2.pdf')
|
|
})
|
|
})
|