decodeNulInJSON walks all string values (and keys) inside a json.RawMessage and applies decodeNulInString.
(raw json.RawMessage)
| 1763 | // decodeNulInJSON walks all string values (and keys) inside a |
| 1764 | // json.RawMessage and applies decodeNulInString. |
| 1765 | func 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 |
no test coverage detected