mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
Invalid \u escapes such as \usepackage were treated as valid, so JSON parsing failed and the partial-json fallback dropped the field and everything after it. They are now kept as literal text like other invalid escapes. fixes #10868
22 lines
820 B
TypeScript
22 lines
820 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { parseStreamingJson } from "../src/utils/json-parse.ts";
|
|
|
|
describe("parseStreamingJson", () => {
|
|
// #10868
|
|
it("keeps invalid \\u escapes as literal text without dropping fields", () => {
|
|
expect(parseStreamingJson(String.raw`{"text":"\url{x}"}`)).toEqual({ text: "\\url{x}" });
|
|
expect(parseStreamingJson(String.raw`{"path":"a.tex","content":"\usepackage{x}","mode":"w"}`)).toEqual({
|
|
path: "a.tex",
|
|
content: "\\usepackage{x}",
|
|
mode: "w",
|
|
});
|
|
});
|
|
|
|
it("decodes valid \\u escapes", () => {
|
|
expect(parseStreamingJson(String.raw`{"text":"caf\u00e9 \url"}`)).toEqual({ text: "café \\url" });
|
|
});
|
|
|
|
it("omits a \\u escape that is cut off mid-stream", () => {
|
|
expect(parseStreamingJson(String.raw`{"text":"ab\u00`)).toEqual({ text: "ab" });
|
|
});
|
|
});
|