Skip to content

Raw C0 control characters in API responses fail in getInto before emitJSON gets called #525

Description

@xsvm

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions