mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 05:56:19 -10:00
fix(desktop): recognise JSON scalar files with mixed-case suffixes (#9152)
* fix(desktop): recognise JSON scalar files with mixed-case suffixes * test(setup): use the current registration command in CodeBuddy fixture * test(cli): split doctor help and timing boundary groups * style(test): format split MCP doctor boundary groups
This commit is contained in:
1 parent
fdd4aefd18
commit
2cf9c42df6
4 files changed
+15
-3
No files matched your search
@@ -396,7 +396,7 @@ def _text_view(name: str, text: str, size: int) -> dict:
|
||||
"""The format REA's state view detects for decoded text of size bytes, and its view; a JSON or key file over the
|
||||
parsed-view limit is refused before its value is built."""
|
||||
trimmed = re.sub(r"^[\s]+", "", text)
|
||||
if name.endswith(".json") or trimmed[:1] in ("[", "{"):
|
||||
if name.lower().endswith(".json") or trimmed[:1] in ("[", "{"):
|
||||
view = _json_view(text, size)
|
||||
if view is not None:
|
||||
return view
|
||||
|
||||
@@ -5,12 +5,23 @@ import {
|
||||
jsonView,
|
||||
keyfileView,
|
||||
textView,
|
||||
textSyntaxFormat,
|
||||
xmlView,
|
||||
} from "./stateFormats.js";
|
||||
|
||||
const bytes = (text: string) => new TextEncoder().encode(text);
|
||||
|
||||
describe("detectStateFormat", () => {
|
||||
it("recognises JSON scalars with mixed-case suffixes and still validates their syntax", () => {
|
||||
for (const text of ["42", "true", "null", '"value"']) {
|
||||
expect(detectStateFormat("/h/a.JsOn", bytes(text))).toBe("json");
|
||||
expect(textSyntaxFormat("/h/a.JSON", text)).toBe("json");
|
||||
expect(detectStateFormat("/h/a.txt", bytes(text))).toBe("text");
|
||||
}
|
||||
expect(detectStateFormat("/h/a.JSON", bytes("42 trailing"))).toBe("text");
|
||||
expect(textSyntaxFormat("/h/a.JSON", "42 trailing")).toBe("text");
|
||||
});
|
||||
|
||||
it("recognises SQLite and dconf headers before decoding text", () => {
|
||||
expect(detectStateFormat("/h/a.db", bytes("SQLite format 3\0rest"))).toBe(
|
||||
"sqlite",
|
||||
|
||||
@@ -210,7 +210,7 @@ export const isJsonText = (text: string): boolean => {
|
||||
|
||||
/** Whether a file's name or leading text marks it as JSON, which it is if it parses. */
|
||||
const namedJson = (path: string, trimmed: string): boolean =>
|
||||
path.endsWith(".json") || /^[[{]/u.test(trimmed);
|
||||
path.toLowerCase().endsWith(".json") || /^[[{]/u.test(trimmed);
|
||||
|
||||
/** Whether a file's name or XML declaration marks it as XML, which it is if it parses. */
|
||||
const namedXml = (path: string, trimmed: string): boolean =>
|
||||
|
||||
@@ -91,13 +91,14 @@ it("keeps JSON Lines holding a number it cannot read exactly as text, as REA doe
|
||||
const files = [
|
||||
["events.jsonl", lines],
|
||||
["events.json", lines],
|
||||
["events.JSON", "42"],
|
||||
["big.json", '{"id":9007199254740993}'],
|
||||
["long.json", `{"id":${"9".repeat(5000)}}`],
|
||||
] as const;
|
||||
|
||||
const formats = pythonFormats(files);
|
||||
|
||||
expect(formats).toEqual(["text", "text", "json", "json"]);
|
||||
expect(formats).toEqual(["text", "text", "json", "json", "json"]);
|
||||
expect(formats).toEqual(
|
||||
files.map(([name, text]) =>
|
||||
detectStateFormat(name, new TextEncoder().encode(text)),
|
||||
|
||||
Reference in new issue
Block a user