Hey Zac!
While looking into how --json handles responses with raw control characters, I noticed an ordering quirk between getInto and �mitJSON.
PR #165 added �scapeJSONStringControlChars in �mitJSON to sanitize unescaped C0 characters (like raw \r in prompt text) so --json wouldn't break jq. But in the current flow, client.getInto() runs json.Unmarshal(raw, out) on the raw bytes before �mitJSON is ever reached.
Because standard �ncoding/json strictly rejects raw control characters in string literals, getInto immediately returns:
ext unexpected response from /api/v1/... (status 200): ...
and the CLI exits with code 1. �mitJSON never runs, so the sanitization in �scapeJSONStringControlChars doesn't actually get a chance to help the caller (I saw your comment in
ead_help.go:57 noting this exact behavior!).
It seems like we could move �scapeJSONStringControlChars down into pkg/civitai/read.go and run it in getInto right before json.Unmarshal(raw, out) if !json.Valid(raw). That way the struct unmarshaling succeeds, and �mitJSON gets already-clean JSON to format.
I've got a patch and a unit test ready for this. Would you be open to a PR?
Hey Zac!
While looking into how --json handles responses with raw control characters, I noticed an ordering quirk between getInto and �mitJSON.
PR #165 added �scapeJSONStringControlChars in �mitJSON to sanitize unescaped C0 characters (like raw \r in prompt text) so --json wouldn't break jq. But in the current flow, client.getInto() runs json.Unmarshal(raw, out) on the raw bytes before �mitJSON is ever reached.
Because standard �ncoding/json strictly rejects raw control characters in string literals, getInto immediately returns:
ext unexpected response from /api/v1/... (status 200): ...and the CLI exits with code 1. �mitJSON never runs, so the sanitization in �scapeJSONStringControlChars doesn't actually get a chance to help the caller (I saw your comment in
ead_help.go:57 noting this exact behavior!).
It seems like we could move �scapeJSONStringControlChars down into pkg/civitai/read.go and run it in getInto right before json.Unmarshal(raw, out) if !json.Valid(raw). That way the struct unmarshaling succeeds, and �mitJSON gets already-clean JSON to format.
I've got a patch and a unit test ready for this. Would you be open to a PR?