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
@@ -36,6 +36,20 @@ describe('core facade (shipped wasm build)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('refuses a lone surrogate with its own kind, never a replacement (L1)', async () => {
|
||||
const core = await nodeCoreRuntime()
|
||||
const zone = JSON.stringify({ annotationId: 'a\ud800', viewId: 'v' })
|
||||
expect(zone).toContain('\\ud800')
|
||||
const refused = core.call('report_zone', zone)
|
||||
expect(refused).toMatchObject({ ok: false, kind: 'lone_surrogate' })
|
||||
expect(JSON.stringify(refused)).not.toContain('\ufffd')
|
||||
const paired = JSON.stringify({ annotationId: 'a😀\\ud800', viewId: 'v' })
|
||||
expect(core.call('report_zone', paired)).toEqual({
|
||||
ok: true,
|
||||
value: { annotationId: 'a😀\\ud800', viewId: 'v' },
|
||||
})
|
||||
})
|
||||
|
||||
it('ships no trap export (the proofs live in pkg-proofs only)', async () => {
|
||||
const glue = (await nodeCoreSource('pkg').importGlue(0)) as unknown as Record<
|
||||
string,
|
||||
|
||||
@@ -25,7 +25,10 @@ export type SheetCheckOutcome =
|
||||
export type SheetValidator = (content: unknown) => SheetCheckOutcome
|
||||
|
||||
export type SheetPublishErrorKind =
|
||||
/** The document does not match the strict schema. */
|
||||
/**
|
||||
* The document does not match the strict schema, or carries a text the core cannot read
|
||||
* without altering it (`lone_surrogate`).
|
||||
*/
|
||||
| 'invalid_shape'
|
||||
/** Integrity errors (warnings never block). */
|
||||
| 'not_publishable'
|
||||
@@ -61,11 +64,17 @@ export class SheetPublishError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
/** The validator's kinds that judge the document itself, not the validator's state. */
|
||||
const CONTENT_KINDS: ReadonlySet<string> = new Set([
|
||||
'invalid_shape',
|
||||
'lone_surrogate',
|
||||
])
|
||||
|
||||
/** Throws unless the validator says the document is publishable. */
|
||||
function assertPublishable(validate: SheetValidator, content: unknown): void {
|
||||
const check = validate(content)
|
||||
if (!check.ok) {
|
||||
throw check.kind === 'invalid_shape'
|
||||
throw CONTENT_KINDS.has(check.kind)
|
||||
? new SheetPublishError('invalid_shape', [], check.detail)
|
||||
: new SheetPublishError('validator_unavailable', [], check.kind)
|
||||
}
|
||||
|
||||
@@ -99,4 +99,15 @@ describe('publishSheetVersion', () => {
|
||||
).rejects.toMatchObject({ kind: 'invalid_shape' })
|
||||
expect(rpcCalls).toEqual([])
|
||||
})
|
||||
|
||||
it('refuses a document carrying a lone surrogate as content, before any RPC (L1)', async () => {
|
||||
const { client, rpcCalls } = stubClient({
|
||||
...publishable,
|
||||
name: { fr: 'Vue \ud800', en: 'View' },
|
||||
})
|
||||
await expect(
|
||||
publishSheetVersion(client, 'v1', validate),
|
||||
).rejects.toMatchObject({ kind: 'invalid_shape' })
|
||||
expect(rpcCalls).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user