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:
bchanot committed 2026-10-14 21:49:39 +02:00
1 parent 20d03cf7fd
commit da8a0370cb
12 files changed
+151 -11

No files matched your search

+2
View File
@@ -103,6 +103,8 @@ function importErrorMessage(err: unknown, t: Translate): string {
return t('home.import.error_attachment_stripped')
case 'no_attachment':
return t('home.import.error_no_attachment')
case 'lone_surrogate':
return t('home.import.error_lone_surrogate')
case 'core_unavailable':
return t('home.import.error_core_unavailable')
}
+2 -1
View File
@@ -82,7 +82,8 @@ export class SheetOps {
/**
* Reads a PDF attachment (any supported shape, as the byte scan parsed it) and rebases
* it on this sheet. Failures: `incompatible_version` (with `found`), `no_attachment`.
* it on this sheet. Failures: `incompatible_version` (with `found`), `no_attachment`,
* `lone_surrogate` (a text the core would alter: refused, never rewritten).
*/
importArchive(attachment: unknown): CoreOutcome<ArchiveImport> {
return this.run('archive.import', attachment)
+2
View File
@@ -52,6 +52,8 @@ export const en: Dict = {
"Report opened on the current sheet, which differs from the archive's. Items not found: {count} (kept with their labels).",
'home.import.error_attachment_stripped':
'This Faunosteo PDF lost its embedded data (attachment removed by a viewer or an optimiser). Use the original file.',
'home.import.error_lone_surrogate':
'This Faunosteo PDF contains malformed text that this version cannot read without altering it. Import refused; the file was not modified.',
'home.no_sheet.title': 'No anatomical sheet',
'home.no_sheet.description':
'This build of the application carries no anatomical sheet: no report can be created or imported.',
+2
View File
@@ -54,6 +54,8 @@ export const fr: Dict = {
"Bilan ouvert sur la fiche actuelle, différente de celle de l'archive. Éléments non retrouvés : {count} (conservés avec leurs libellés).",
'home.import.error_attachment_stripped':
"Ce PDF Faunosteo a perdu ses données embarquées (pièce jointe supprimée par un lecteur ou un optimiseur). Utilisez le fichier d'origine.",
'home.import.error_lone_surrogate':
"Ce PDF Faunosteo contient un texte mal encodé que cette version ne peut pas relire sans l'altérer. Import refusé ; le fichier n'a pas été modifié.",
'home.no_sheet.title': 'Aucune fiche anatomique',
'home.no_sheet.description':
"Cette version de l'application n'embarque aucune fiche anatomique : aucun bilan ne peut être créé ni importé.",
+12 -2
View File
@@ -8,7 +8,14 @@ import type { SheetIndex } from '@/services/sheetIndex'
export { MAX_PDF_BYTES } from '@faunosteo/pdf'
export type ImportErrorKind = ArchiveReadErrorKind | 'core_unavailable'
/**
* `lone_surrogate`: the attachment escapes a lone UTF-16 surrogate, which the
* core cannot read without altering it (L1): refused, the file untouched.
*/
export type ImportErrorKind =
| ArchiveReadErrorKind
| 'core_unavailable'
| 'lone_surrogate'
/**
* Localization-agnostic import error. Carries a kind discriminant + an
@@ -46,7 +53,8 @@ export async function readAttachment(pdfBytes: Uint8Array): Promise<unknown> {
* attachment (report first, v2 migrated through the sheet's map, then the
* envelope kept or its snapshot dropped with a reason) and the rebase onto
* that sheet. An unknown numeric report version is `incompatible_version`,
* any other unreadable content `no_attachment`, as the engine reported them.
* a text the core would alter `lone_surrogate`, any other unreadable content
* `no_attachment`, as the engine reported them.
*/
export function importAttachment(
attachment: unknown,
@@ -59,6 +67,8 @@ export function importAttachment(
throw new ImportError('incompatible_version', outcome.found ?? null)
case 'no_attachment':
throw new ImportError('no_attachment')
case 'lone_surrogate':
throw new ImportError('lone_surrogate')
case 'core_unavailable':
case 'internal':
throw new ImportError('core_unavailable')
+13 -2
View File
@@ -53,7 +53,7 @@ export interface ActionResult {
/** What a draft restore did; `null` from the action when there was nothing to restore. */
export type RestoreResult =
| { kind: 'restored'; rebase: RebaseOutcome }
/** The draft is unreadable by this build: set aside under a quarantine key. */
/** The draft is unreadable by this build: set aside, verbatim, under a quarantine key. */
| { kind: 'quarantined' }
/**
* The draft is unreadable but could not be set aside (storage full): it stays in
@@ -123,6 +123,17 @@ function applyCore(
return OK
}
/**
* The core's content kinds for a draft: the text itself is unreadable by this build
* (`lone_surrogate`: reading it would alter a string, L1). Any other failure is the core's
* or the sheet's and leaves the draft in place.
*/
const UNREADABLE_DRAFT_KINDS: ReadonlySet<string> = new Set([
'invalid',
'unsupported_version',
'lone_surrogate',
])
/** Reads the draft through the core; unreadable content goes to quarantine, never away. */
function restore(
index: SheetIndex,
@@ -135,7 +146,7 @@ function restore(
const outcome = index.ops.restoreDraft(draft, archiveText)
if (!outcome.ok) {
// Only an unreadable draft is set aside; a core or sheet failure leaves it in place.
if (outcome.kind !== 'invalid' && outcome.kind !== 'unsupported_version') {
if (!UNREADABLE_DRAFT_KINDS.has(outcome.kind)) {
return { result: { kind: 'core_unavailable' } }
}
const setAside = quarantine('draft', draft, DRAFT_KEY)