git.lukeshu.com/go/lowmemjson@v0.3.9-0.20230723050957-72f6d13f6fb2/ReleaseNotes.md (about) 1 # v0.3.8 (2023-02-25) 2 3 Theme: Fixes from fuzzing (part 3/?) 4 5 User-facing changes: 6 7 - Change: Encoder: When encoding a `map`, sort the key:value pairs 8 by the pre-string-encoded key rather than the post-string-encoded 9 key. For instance, now `""` sorts before `" "`. 10 11 # v0.3.8 (2023-02-25) 12 13 Theme: Fixes from fuzzing (part 2/?) 14 15 User-facing changes: 16 17 - Feature: There is a new `DecodeString` helper function. 18 19 - Change: Decoder: No longer bails when a type error 20 (`DecodeTypeError`) is encountered. The part of the output value 21 with the type error is either unmodified (if already existing) or 22 set to nil/zero (if not already existing), and decoding 23 continues. If no later fatal error (syntax, I/O) is encountered, 24 then the first type error encountered is returned. This is 25 consistent with the behavior of `encoding/json`. 26 27 - Change: Several error strings have been reworded to match 28 `encoding/json`. 29 30 - Bugfix: Decoder: If there is a syntax error in a byte that 31 invalid UTF-8, include that byte value in the error message 32 rather than including the U+FFFD Unicode replacement character. 33 34 - Bugfix: Syntax errors on raw-bytes (for invalid UTF-8) no longer 35 show the raw byte as a `\u00XX` Unicode codepoint, but now as a 36 `\xXX` byte. 37 38 - Bugfix: compat/json: `io.EOF` is now correctly converted to 39 "unexpected end of JSON input", same as `io.ErrUnexpectedEOF`. 40 41 - Bugfix: ReEncoder: Don't count bytes already in the UTF-8 decode 42 buffer toward the number of bytes returned from `.Write` and 43 `.WriteString`. This only comes up if there is an I/O causing a 44 partial write. 45 46 - Bugfix: ReEncoder: The error messages for trailing partial UTF-8 47 now reflect the `InvalidUTF8` setting, rather than simply saying 48 "unflushed unicode garbage". 49 50 - Bugfix: No longer allows a comma after the last key:value pair in 51 an object. 52 53 # v0.3.7 (2023-02-20) 54 55 Theme: Fixes from fuzzing (part 1?) 56 57 User-facing changes: 58 59 - General Changes: 60 61 + Change: ReEncoder: No longer compact floating-point numbers by 62 default, add a `CompactFloats` ReEncoderConfig option to 63 control this. 64 65 + Bugfix: Encoder, ReEncoder: Now correctly trims unnecessary 66 the trailing '0's from the fraction-part when compacting 67 numbers. 68 69 + Bugfix: Decoder: Decoding `json.Unmarshaler` or 70 `lowmemjson.Decodable` as a top-level value no longer needs to 71 read past the closing `"`/`]`/`}`; this can be significant 72 when reading streaming input, as that next read may block. 73 74 - Compatibility bugfixes: 75 76 + compat/json.Valid: No longer considers truncated JSON 77 documents to be valid. 78 79 + compat/json.Compact, compat/json.Indent: Don't write to the 80 destination buffer if there is a syntax error. 81 82 + compat/json.Compact, compat/json.Indent: No longer compact 83 floating-point numbers; as `encoding/json` doesn't. 84 85 + compat/json.HTMLEscape: Just look for problematic UTF-8 runes, 86 don't actually parse as JSON. This is consistent with the 87 function's lack of an `error` return value, and with the 88 behavior of `encoding/json`. 89 90 + compat/json.Indent: Preserve trailing whitespace, same as 91 `encoding/json`. 92 93 + compat/json.Decoder: No longer transforms "unexpected EOF" 94 errors to "unexpected end of JSON input". This makes it 95 different than `compat/json.Unmarshal`, but the same as 96 `encoding/json`. 97 98 + compat/json.Decoder, compat/json.Unmarshal: No longer mutate 99 the target value at all if there is a syntax error in the 100 input. 101 102 - Unicode: 103 104 + Feature: Encoder, ReEncoder: Add an `InvalidUTF8` 105 ReEncoderConfig option and `BackslashEscapeRawByte` 106 BackslashEscapeMode to allow emitted strings to contain 107 invalid UTF-8. 108 109 + Feature: ReEncoder: No longer unconditionally normalizes 110 `\uXXXX` hex characters to lower-case; now this is controlled 111 by the `BackslashEscaper` (and the default is now to leave the 112 capitalization alone). 113 114 + Change: EscapeDefault, EscapeDefaultNonHTMLSafe: No longer 115 force long Unicode `\uXXXX` sequences for the U+FFFD Unicode 116 replacement character. 117 118 + Change: Encoder: Unless overridden by the BackslashEscaper, 119 now by default uses `\uXXXX` sequences when emitting the 120 U+FFFD Unicode replacement character in place of invalid 121 UTF-8. 122 123 + Bugfix: Encoder, ReEncoder: Fix an issue with decoding UTF-8 124 that when a codepoint straddles a write boundary it is 125 interpreted as a sequence of U+FFFD runes. 126 127 + Bugfix: compat/json.Valid: Do not consider JSON containing 128 invalid UTF-8 to be valid (this is different than 129 `encoding/json` at the time of this writing; but I consider 130 that to be a bug in `encoding/json`; [go#58517][]). 131 132 + Bugfix: compat/json.Compact, compat/json.Indent: Don't munge 133 invalid UTF-8 in strings; as `encoding/json` doesn't. 134 135 [go#58517]: https://github.com/golang/go/issues/58517 136 137 # v0.3.6 (2023-02-16) 138 139 Theme: Architectural improvements 140 141 User-facing changes: 142 143 - Change: ReEncoder: The ReEncoderConfig struct member is no longer 144 public. 145 146 - Change: ReEncoder: `WriteRune` may now be called even if there is 147 a partial UTF-8 codepoint from a `Write` or `WriteString` call, 148 but now simply returns the width of the rune, rather than the 149 number of bytes actually written. 150 151 - Feature: `Number` and `RawMessage` type aliases are now 152 available, so that a user of lowmemjson's native APIs does not 153 need to import `encoding/json` or compat/json in order to use 154 them. 155 156 - Bugfix: Encoder, ReEncoder: If there was an error writing to the 157 output stream, it may have returned a `*ReEncodeSyntaxError` even 158 though it's not a syntax issue, or may have returned the 159 underlying error without wrapping it. If there is an error 160 writing to the output, Encoder and ReEncoder now return 161 `*EncodeWriteError` and `*ReEncodeWriteError` respectively. 162 163 # v0.3.5 (2023-02-10) 164 165 Theme: Compatibility bugfixes 166 167 User-facing changes: 168 169 - Decoder: Fixes a bug where if an EOF is encountered, the reader 170 is appended to, then another Decode is attempted, that EOF 171 poisons future Decodes. This is something that `encoding/json` 172 supports. 173 174 - Encoder: Fixes a bug where if an encode error is encountered, all 175 future Encode calls will fail. Reusing an Encoder is something 176 that `encoding/json` supports. 177 178 - compat/json.Encoder: Now buffers the output, to avoid partial 179 writes if an encode error is encountered. This matches the 180 behavior of `encoding/json`. For memory consumption reasons, the 181 native lowmemjson Encoder still does not buffer. 182 183 # v0.3.4 (2023-02-05) 184 185 Theme: Fix compilation with Go 1.20 186 187 lowmemjson uses git.lukeshu.com/go/typedsync.CacheMap (since 188 lowmemjson v0.3.1), which when compiled with Go 1.20 makes use of Go 189 1.20 language features. However, because lowmemjson's `go.mod` said 190 `go 1.18`, those language features are disabled and compilation 191 fails (see [go#58342][]). To work around this, lowmemjson's 192 `go.mod` now says `go 1.20`. Despite this, lowmemjson still works 193 fine with Go 1.18. 194 195 [go#58342]: https://github.com/golang/go/issues/58342 196 197 # v0.3.3 (2023-02-04) 198 199 Theme: Bugfix 200 201 User-facing changes: 202 203 - ReEncoder: Fixes a regression in v0.3.1 where it erroneously 204 enters compact mode when CompactIfUnder is set and write barriers 205 are in use. 206 207 - ReEncoder: Fixes a regression in v0.3.1 where it sometimes emits 208 extra (but syntactically valid) newlines when write barriers are 209 in use. 210 211 # v0.3.2 (2023-02-03) 212 213 Theme: Bugfix 214 215 User-facing changes: 216 217 - ReEncoder: Fixes a regression in v0.3.1 where it sometimes emits 218 extra (but syntactically valid) newlines. 219 220 # v0.3.1 (2023-01-31) 221 222 Theme: Performance 223 224 This release does a bunch of performance tuning and optimizations, 225 with no user-visible changes other than memory consumption and CPU 226 time. Based on benchmarks with a real-world use-case, it is now 227 roughly an order of magnitude faster, with much lower memory 228 consumption (the big-O of memory consumption was always pretty low, 229 but there were some big constant factors before). 230 231 # v0.3.0 (2023-01-30) 232 233 Theme: Breaking changes 234 235 This release makes a breaking change to the way *ReEncoder works. 236 This change both better fits what's convenient to use, and enables 237 making future performance improvements. 238 239 Breaking changes: 240 241 - ReEncoder: Instead of instantiating a `*ReEncoder` with 242 243 ```go 244 reenc := &lowmemjson.ReEncoder{Out: w, settings} 245 ``` 246 247 it is now instantiated with 248 249 ```go 250 reenc := lowmemjson.NewReEncoder(w, lowmemjson.ReEncoderConfig{settings}) 251 ``` 252 253 # v0.2.1 (2023-01-30) 254 255 Theme: Code quality 256 257 This release improves code quality; getting various linters to pass, 258 adding tests (and a few bug-fixes), refactoring things to be 259 clearer, fixing some mistakes in the documentation. 260 261 User-facing changes: 262 263 - Encoder: `*EncodeMethodError` is now also used when a method 264 produces invalid JSON. 265 - Decoder: The offset in `*DecodeTypeError`s now correctly point 266 the start of the value, rather than somewhere in the middle of 267 it. 268 269 # v0.2.0 (2023-01-26) 270 271 Theme: Add documentation 272 273 This release doesn't make any major changes, and is just adding 274 documentation. I have removed a few minor things that I didn't want 275 to write documentation for. 276 277 Breaking changes: 278 279 - Drop the following shorthand functions: 280 + `func Decode(r io.RuneScanner, ptr any) error { return NewDecoder(r).Decode(ptr) }` 281 + `func DecodeThenEOF(r io.RuneScanner, ptr any) error { return NewDecoder(r).DecodeThenEOF(ptr) }` 282 + `func Encode(w io.Writer, obj any) (err error) { return NewEncoder(w).Encode(obj) }` 283 - Drop `const Tab = "\t"`. 284 285 # v0.1.0 (2022-09-19) 286 287 Theme: Initial release