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
@@ -6,6 +6,7 @@
|
||||
clippy::expect_used
|
||||
)]
|
||||
|
||||
use faunosteo_core::domain::js::{find_lone_surrogate, parse_json};
|
||||
use serde_json::Value;
|
||||
|
||||
/// A repository file, by path from the repository root.
|
||||
@@ -14,6 +15,25 @@ pub fn repo_file(relative: &str) -> String {
|
||||
std::fs::read_to_string(&path).unwrap_or_else(|error| panic!("{path}: {error}"))
|
||||
}
|
||||
|
||||
/// A frozen oracle file (`crates/core/tests/oracles/<name>`): its text and its value. The
|
||||
/// TypeScript outputs it freezes keep the lone surrogate escapes `JSON.parse` kept (the L1
|
||||
/// cases), which the core refuses to read; each one is read here as literal text (`\\uD800`
|
||||
/// spelt out), never replaced, so the raw text stays the evidence of what TypeScript did.
|
||||
pub fn oracle_file(name: &str) -> (String, Value) {
|
||||
let text = repo_file(&format!("crates/core/tests/oracles/{name}"));
|
||||
let mut spelt = String::with_capacity(text.len());
|
||||
let mut rest = text.as_str();
|
||||
while let Some(at) = find_lone_surrogate(rest) {
|
||||
spelt.push_str(&rest[..at]);
|
||||
spelt.push('\\');
|
||||
spelt.push_str(&rest[at..at + 6]);
|
||||
rest = &rest[at + 6..];
|
||||
}
|
||||
spelt.push_str(rest);
|
||||
let value = parse_json(&spelt).unwrap();
|
||||
(text, value)
|
||||
}
|
||||
|
||||
/// A Zod oracle (`crates/core/tests/oracles/<name>`): its source file and the Zod output in
|
||||
/// the JavaScript pretty form.
|
||||
pub fn zod_oracle(name: &str) -> (String, String) {
|
||||
|
||||
Reference in new issue
Block a user