3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 23:25:43 +01:00

Answer stability round 1: read JSON with the library's own reader, since V8's JSON.parse misreads an escaped key

This commit is contained in:
2026-10-08 12:24:30 +02:00
committed by Lillem4n
parent bfe26dd438
commit d7ba149b83
5 changed files with 214 additions and 15 deletions
+1 -9
View File
@@ -9,6 +9,7 @@ import { infoStringCarries } from './commonmark/grammar.ts'
import { isAdfNode } from '../adf/document.ts'
import { isJsonValue, nestingDepth, overNested } from '../json-value.ts'
import { largestNesting } from '../nesting.ts'
import { parseJsonText } from '../json-text.ts'
import { serializeCanonicalJson } from '../canonical-json.ts'
export const carryFencePrefix = 'adf:'
@@ -91,12 +92,3 @@ function typedValue(value: JsonValue, type: string): Read<JsonValue> {
if ('type' in value) return { fault: unsupportedNodeShape(`the ${carryFencePrefix}${type} fence names its node's type: this JSON holds a type as well; ${fenceEscape(type)}`) }
return { value: { ...value, type } }
}
function parseJsonText(raw: string): { value: unknown } | undefined {
try {
const value: unknown = JSON.parse(raw)
return { value }
} catch {
return undefined
}
}