|
3391 | 3391 | java.io.PushbackReader or some derivee. stream defaults to the |
3392 | 3392 | current value of *in*. |
3393 | 3393 |
|
3394 | | - In the :default mode, governed by *read-eval*, reading of class objects, |
3395 | | - vars, namespaces are allowed, as well as static methods and |
3396 | | - constructors of derivees of the *read-whitelist* |
| 3394 | + Note that read can execute code (controlled by *read-eval*), |
| 3395 | + and as such should be used only with trusted sources. |
3397 | 3396 |
|
3398 | | - See also - safe-read" |
| 3397 | + For data structure interop use read-edn" |
3399 | 3398 | {:added "1.0" |
3400 | 3399 | :static true} |
3401 | 3400 | ([] |
|
3405 | 3404 | ([stream eof-error? eof-value] |
3406 | 3405 | (read stream eof-error? eof-value false)) |
3407 | 3406 | ([stream eof-error? eof-value recursive?] |
3408 | | - (. clojure.lang.LispReader (read stream (boolean eof-error?) eof-value recursive?)))) |
| 3407 | + (. clojure.lang.LispReader (read stream (boolean eof-error?) eof-value recursive?)))) |
3409 | 3408 |
|
3410 | | -(defn safe-read |
3411 | | - "Same as read, with *read-eval* bound to false" |
| 3409 | +(defn read-edn |
| 3410 | + "Reads the next object from stream, which must be an instance of |
| 3411 | + java.io.PushbackReader or some derivee. stream defaults to the |
| 3412 | + current value of *in*. |
| 3413 | +
|
| 3414 | + Reads data in the edn format (subset of Clojure data): |
| 3415 | + http://edn-format.org" |
3412 | 3416 | {:added "1.5"} |
3413 | | - [& args] |
3414 | | - (binding [*read-eval* false] |
3415 | | - (apply read args))) |
| 3417 | + ([] |
| 3418 | + (read *in*)) |
| 3419 | + ([stream] |
| 3420 | + (read stream true nil)) |
| 3421 | + ([stream eof-error? eof-value] |
| 3422 | + (read stream eof-error? eof-value false)) |
| 3423 | + ([stream eof-error? eof-value recursive?] |
| 3424 | + (. clojure.lang.EdnReader (read stream (boolean eof-error?) eof-value recursive?)))) |
3416 | 3425 |
|
3417 | 3426 | (defn read-line |
3418 | 3427 | "Reads the next line from stream that is the current value of *in* ." |
|
3426 | 3435 | (defn read-string |
3427 | 3436 | "Reads one object from the string s. |
3428 | 3437 |
|
3429 | | - In the :default mode, governed by *read-eval*, reading of class objects, |
3430 | | - vars, namespaces are allowed, as well as static methods and |
3431 | | - constructors of derivees of the *read-whitelist* |
3432 | | -
|
3433 | | - Returns nil when string is nil or empty. |
| 3438 | + Note that read-string can execute code (controlled by *read-eval*), |
| 3439 | + and as such should be used only with trusted sources. |
3434 | 3440 |
|
3435 | | - See also - safe-read-string" |
| 3441 | + For data structure interop use read-edn-string" |
3436 | 3442 | {:added "1.0" |
3437 | 3443 | :static true} |
3438 | | - [^String s] (when (pos? (count s)) (clojure.lang.RT/readString s))) |
| 3444 | + [s] (clojure.lang.RT/readString s)) |
| 3445 | + |
| 3446 | +(defn read-edn-string |
| 3447 | + "Reads one object from the string s. Returns nil when s is nil or empty. |
3439 | 3448 |
|
3440 | | -(defn safe-read-string |
3441 | | - "Same as read-string, with *read-eval* bound to false" |
| 3449 | + Reads data in the edn format (subset of Clojure data): |
| 3450 | + http://edn-format.org" |
3442 | 3451 | {:added "1.5"} |
3443 | | - [s] |
3444 | | - (binding [*read-eval* false] |
3445 | | - (read-string s))) |
| 3452 | + [s] (when (pos? (count s)) (clojure.lang.EdnReader/readString s))) |
3446 | 3453 |
|
3447 | 3454 | (defn subvec |
3448 | 3455 | "Returns a persistent vector of the items in vector from |
|
5899 | 5906 | {:added "1.0"}) |
5900 | 5907 |
|
5901 | 5908 | (add-doc-and-meta *read-eval* |
5902 | | - "When set to logical false in the thread-local binding, #= reading is disabled. |
5903 | | - Example: |
5904 | | - (binding [*read-eval* false] (read-string \"#=(not allowed)\")) |
5905 | | -
|
5906 | | - Defaults to :default |
| 5909 | + "When set to logical false in the thread-local binding, |
| 5910 | + the eval reader (#=(...)) is disabled in read/load. |
| 5911 | + Example: (binding [*read-eval* false] (read-string \"#=(eval (def x 3))\")) |
5907 | 5912 |
|
5908 | | - In :default mode, reading of class objects, vars, namespaces are allowed, as well as |
5909 | | - static methods and constructors of derivees of the *read-whitelist*. |
5910 | | -
|
5911 | | - When set to true in the thread-local binding, the eval |
5912 | | - reader (#=(...)) for arbitrary expressions is enabled in read/load. |
5913 | | - " |
| 5913 | + Defaults to true" |
5914 | 5914 | {:added "1.0"}) |
5915 | 5915 |
|
5916 | | -(add-doc-and-meta *read-whitelist* |
5917 | | - "In the reader's :default *read-eval* mode, |
5918 | | - reading of static methods and constructors of derivees of the |
5919 | | - *read-whitelist* is alowed. |
5920 | | -
|
5921 | | - Defaults to [java.util.Map, java.util.Collection, java.lang.Number]" |
5922 | | - |
5923 | | - {:added "1.5"}) |
5924 | | - |
5925 | 5916 | (defn future? |
5926 | 5917 | "Returns true if x is a future" |
5927 | 5918 | {:added "1.1" |
|
0 commit comments