File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed
main/clojure/clojure/data
test/clojure/clojure/data Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,8 @@ Change Log
151
151
----------------------------------------
152
152
153
153
* next
154
- * In ` read ` , update docstring to specify minimum buffer size if PushbackReader supplied
154
+ * Fix: ` read ` of number followed by EOF can break subsequent read from seeing EOF
155
+ * In ` read ` , update docstring to specify minimum buffer size when PushbackReader supplied
155
156
* Release [ 2.5.0] on 2023-Dec-21
156
157
* Fix [ DJSON-50] : ` read ` can take a PushbackReader for repeated read use case
157
158
* Fix ` write ` docstring to add ` :indent ` option added in [ DJSON-18]
Original file line number Diff line number Diff line change 33
33
(readChars [_ buffer start bufflen]
34
34
(.read rdr ^chars buffer start bufflen))
35
35
(unreadChar [_ c]
36
+ ; ; ASSERT: c should never be -1 (EOF)
36
37
(.unread rdr c))
37
38
(unreadChars [_ buffer start bufflen]
38
39
(.unread rdr buffer start bufflen))
63
64
(.getChars ^String s p end ^chars buffer start)))
64
65
(if (pos? n) n -1 )))
65
66
(unreadChar [_ _c]
67
+ ; ; ASSERT: c should never be -1 (EOF)
66
68
(set! pos (unchecked-dec pos))
67
69
nil )
68
70
(unreadChars [_ _buffer _start bufflen]
234
236
:whitespace
235
237
(do (.unreadChar stream c)
236
238
false )
237
- (\, \] \} -1 )
239
+ (\, \] \})
238
240
(do (.unreadChar stream c)
239
241
false )
242
+ -1
243
+ false
240
244
(throw (Exception. " JSON error (invalid number literal)" )))
241
245
; ; previous character is a "0"
242
246
:frac-point
251
255
:whitespace
252
256
(do (.unreadChar stream c)
253
257
false )
254
- (\, \] \} -1 )
258
+ (\, \] \})
255
259
(do (.unreadChar stream c)
256
260
false )
261
+ -1
262
+ false
257
263
; ; Disallow zero-padded numbers or invalid characters
258
264
(throw (Exception. " JSON error (invalid number literal)" )))
259
265
; ; previous character is a "."
276
282
:whitespace
277
283
(do (.unreadChar stream c)
278
284
true )
279
- (\, \] \} -1 )
285
+ (\, \] \})
280
286
(do (.unreadChar stream c)
281
287
true )
288
+ -1
289
+ true
282
290
(throw (Exception. " JSON error (invalid number literal)" )))
283
291
; ; previous character is a "e" or "E"
284
292
:exp-symbol
306
314
:whitespace
307
315
(do (.unreadChar stream c)
308
316
true )
309
- (\, \] \} -1 )
317
+ (\, \] \})
310
318
(do (.unreadChar stream c)
311
319
true )
320
+ -1
321
+ true
312
322
(throw (Exception. " JSON error (invalid number literal)" ))))))]
313
323
(if decimal?
314
324
(read-decimal (str buffer) bigdec?)
Original file line number Diff line number Diff line change 27
27
(is (= {" foo" " some string" } (json/read pbr)))
28
28
(is (= {" foo" " another long ......................................................... string" } (json/read pbr)))))
29
29
30
+ (defn read-then-eof [s]
31
+ (let [r (pbr s)
32
+ val (json/read r :eof-error? false :eof-value :EOF )]
33
+ (is (= :EOF (json/read r :eof-error? false :eof-value :EOF )))
34
+ val))
35
+
36
+ (deftest read-multiple-eof
37
+ (are [expected s] (= expected (read-then-eof s))
38
+ 1.2 " 1.2"
39
+ 0 " 0"
40
+ 1 " 1"
41
+ 1.0 " 1.0"
42
+ " abc" " \" abc\" "
43
+ " \u 2202" " \"\u 2202\" "
44
+ [] " []"
45
+ [1 2 ] " [1, 2]" )
46
+ )
47
+
30
48
(deftest read-from-reader
31
49
(let [s (java.io.StringReader. " 42" )]
32
50
(is (= 42 (json/read s)))))
You can’t perform that action at this time.
0 commit comments