MCPcopy Create free account
hub / github.com/coder/coder / decodeNulInJSON

Function decodeNulInJSON

coderd/x/chatd/chatprompt/chatprompt.go:1765–1784  ·  view source on GitHub ↗

decodeNulInJSON walks all string values (and keys) inside a json.RawMessage and applies decodeNulInString.

(raw json.RawMessage)

Source from the content-addressed store, hash-verified

1763// decodeNulInJSON walks all string values (and keys) inside a
1764// json.RawMessage and applies decodeNulInString.
1765func decodeNulInJSON(raw json.RawMessage) json.RawMessage {
1766 if len(raw) == 0 {
1767 return raw
1768 }
1769 // U+E000 encoded as UTF-8 is 0xEE 0x80 0x80.
1770 if !bytes.Contains(raw, []byte{0xEE, 0x80, 0x80}) {
1771 return raw
1772 }
1773 dec := json.NewDecoder(bytes.NewReader(raw))
1774 dec.UseNumber()
1775 var v any
1776 if err := dec.Decode(&v); err != nil {
1777 return raw
1778 }
1779 result, err := json.Marshal(decodeNulInValue(v))
1780 if err != nil {
1781 return raw
1782 }
1783 return result
1784}
1785
1786// encodeNulInParts returns a shallow copy of parts with all
1787// string and json.RawMessage fields NUL-encoded. The caller's

Callers 1

decodeNulInPartsFunction · 0.85

Calls 3

decodeNulInValueFunction · 0.85
ContainsMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected