Byte-array <-> bytevector interop + charset-aware (String. bytes cs)
The host carries bytes two ways: Chez bytevectors (what String/.getBytes produce) and jolt byte-arrays (what byte-array / the Java-array shims use). They didn't interconvert, so code mixing the two — like clj-http-lite, which buffers into (byte-array n) but encodes via .getBytes and decodes via (String. ^[B body charset) — broke. - byte-array now also accepts a bytevector or a string (UTF-8 bytes), so the two representations convert freely at interop seams. - (String. bytes [charset]) decodes a bytevector OR a jolt byte-array with the named charset (UTF-8 default; ISO-8859-1/latin1/ascii = one byte/char). It previously only took a bytevector and ignored the charset. Runtime .ss shims, no re-mint. Unit covers both directions + charset.
This commit is contained in:
parent
c5e1e0544a
commit
3253df979a
3 changed files with 44 additions and 5 deletions
|
|
@ -465,4 +465,11 @@
|
|||
{:suite "hostshim" :expr "(do (__register-class-ctor! \"Box4\" (fn [] (jolt.host/tagged-table :my/box4))) (__register-instance-check! (fn [cn val] (if (= cn \"Box4\") (= :my/box4 (jolt.host/ref-get val :jolt/type)) nil))) (instance? Box4 \"not-a-box\"))" :expected "false"}
|
||||
{:suite "hostshim" :expr "(jolt.host/table? (jolt.host/tagged-table :t))" :expected "true"}
|
||||
{:suite "hostshim" :expr "(jolt.host/table? \"x\")" :expected "false"}
|
||||
{:suite "bytes" :expr "(seq (byte-array \"hi\"))" :expected "(104 105)"}
|
||||
{:suite "bytes" :expr "(seq (byte-array (.getBytes \"AB\" \"UTF-8\")))" :expected "(65 66)"}
|
||||
{:suite "bytes" :expr "(alength (byte-array (.getBytes \"hello\" \"UTF-8\")))" :expected "5"}
|
||||
{:suite "bytes" :expr "(String. (byte-array [104 105]))" :expected "hi"}
|
||||
{:suite "bytes" :expr "(String. (byte-array [104 105]) \"UTF-8\")" :expected "hi"}
|
||||
{:suite "bytes" :expr "(int (first (String. (byte-array [200]) \"ISO-8859-1\")))" :expected "200"}
|
||||
{:suite "bytes" :expr "(String. (.getBytes \"round\" \"UTF-8\") \"UTF-8\")" :expected "round"}
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue