fix(app): set lone-surrogate texts aside or refuse them with a message (L1)
A draft the core refuses as lone_surrogate is unreadable content: it
goes to osteo:quarantine:draft verbatim with the existing notice. An
import is refused as ImportError('lone_surrogate') with the owner's
wording (home.import.error_lone_surrogate, FR/EN), the file untouched.
The publish gate reads the kind as invalid_shape. Tests on the real
core: quarantine keeps the exact text, an editor action leaves the
report as it was, normal text with pairs and literal backslashes reads
unchanged.
This commit is contained in:
1 parent
20d03cf7fd
commit
da8a0370cb
12 files changed
+151
-11
No files matched your search
@@ -7,9 +7,14 @@
|
||||
*/
|
||||
import { describe, it, expect, beforeAll } from 'vitest'
|
||||
import { PDFDocument } from 'pdf-lib'
|
||||
import { importReportFromPdf, ImportError, MAX_PDF_BYTES } from '@/pdf/import'
|
||||
import {
|
||||
importAttachment,
|
||||
importReportFromPdf,
|
||||
ImportError,
|
||||
MAX_PDF_BYTES,
|
||||
} from '@/pdf/import'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { loadTestSheet } from '../helpers/sheet'
|
||||
import { loadTestSheet, minimalReport } from '../helpers/sheet'
|
||||
|
||||
let sheet: SheetIndex
|
||||
beforeAll(async () => {
|
||||
@@ -46,3 +51,24 @@ describe('importReportFromPdf error kinds', () => {
|
||||
await rejectsWith(new Uint8Array(MAX_PDF_BYTES + 1), 'invalid_pdf')
|
||||
})
|
||||
})
|
||||
|
||||
describe('importAttachment on the core (L1)', () => {
|
||||
it('refuses an attachment with a lone surrogate as lone_surrogate, never rewritten', () => {
|
||||
for (const text of ['a\ud800b', '\udfff']) {
|
||||
const attachment = minimalReport(sheet, { conclusion: text })
|
||||
expect(() => importAttachment(attachment, sheet)).toThrow(
|
||||
expect.objectContaining({ kind: 'lone_surrogate' }),
|
||||
)
|
||||
expect(attachment.conclusion).toBe(text)
|
||||
}
|
||||
})
|
||||
|
||||
it('imports normal text with pairs and literal backslashes unchanged', () => {
|
||||
const text = 'é 😀 \\ud800 \ufffd'
|
||||
const imported = importAttachment(
|
||||
minimalReport(sheet, { conclusion: text }),
|
||||
sheet,
|
||||
)
|
||||
expect(imported.rebase.report.conclusion).toBe(text)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user