fix(domain): refuse lone UTF-16 surrogates instead of replacing them (L1)
serde_json already refuses a lone surrogate escape; the U+FFFD pre-pass is gone and parse_json classifies the refusal (strict escape scan, on failure only) so callers name it: closed kind lone_surrogate from operation inputs, sheet.check, draft.restore and archive.import. Oracles untouched: the two L1 cases and the Zod verdict now assert that TypeScript kept the surrogate and Rust refuses the text.
This commit is contained in:
1 parent
36316cf67f
commit
20d03cf7fd
9 files changed
+275
-75
No files matched your search
@@ -105,7 +105,7 @@ pub fn free(op: &str, input: &str) -> Option<Outcome> {
|
||||
}
|
||||
|
||||
fn sheet_check(input: &str) -> Outcome {
|
||||
let document = parse_json(input).map_err(|error| Failure::new("invalid_json", error))?;
|
||||
let document = parse_json(input)?;
|
||||
let check =
|
||||
check_sheet_document(document).map_err(|error| Failure::new("invalid_shape", error))?;
|
||||
to_value(&check)
|
||||
@@ -306,14 +306,15 @@ fn versioned(kind: &'static str, found: Option<f64>) -> Failure {
|
||||
}
|
||||
}
|
||||
|
||||
/// Content kinds (`invalid`, `unsupported_version`) mean the draft itself is unreadable:
|
||||
/// the caller sets it aside. `rebase_failed` is a defect of the loaded sheet, never of the
|
||||
/// Content kinds (`invalid`, `unsupported_version`, `lone_surrogate`) mean the draft itself
|
||||
/// is unreadable: the caller sets it aside, verbatim. `rebase_failed` is a defect of the loaded sheet, never of the
|
||||
/// draft, and leaves it where it is.
|
||||
fn draft_restore(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
let input: DraftRestoreInput = parse_input(input)?;
|
||||
session::restore_draft(sheet, &input.draft, input.archive.as_deref())
|
||||
.map_err(|failure| match failure {
|
||||
RestoreFailure::UnsupportedVersion(found) => versioned("unsupported_version", found),
|
||||
RestoreFailure::LoneSurrogate(detail) => Failure::new("lone_surrogate", detail),
|
||||
RestoreFailure::Invalid(detail) => Failure::new("invalid", detail),
|
||||
RestoreFailure::Rebase(detail) => Failure::new("rebase_failed", detail),
|
||||
})
|
||||
@@ -328,6 +329,7 @@ fn archive_import(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
versioned("incompatible_version", Some(found))
|
||||
}
|
||||
ImportFailure::NoAttachment => Failure::new("no_attachment", ""),
|
||||
ImportFailure::LoneSurrogate(detail) => Failure::new("lone_surrogate", detail),
|
||||
ImportFailure::Invalid(detail) => Failure::new("invalid", detail),
|
||||
})
|
||||
.and_then(|import| to_value(&import))
|
||||
|
||||
Reference in new issue
Block a user