unisonweb / base

Unison base libraries
https://share.unison-lang.org/@unison/base
18 stars 6 forks source link

regression in Bytes.toHex #159

Closed ceedubs closed 1 year ago

ceedubs commented 1 year ago

Fairly recently there has been a change to the implementation of Bytes.toHex in base, and it has introduced a regression for any byte whose value is less than 0x10.

Example:

    1 | > lib.base.Bytes.toHex 0xs0101
          ⧩
          "11"

Here 0xs0101 represents two bytes: 01 01. But Bytes.toHex treats it as though it is the single byte 0x11 (17 in decimal notation). The problem is that each byte should be left-padded with 0 if it is a single character.

This problem did not exist with the previous implementation of Bytes.toHex:

    3 | > catch do 0xs0101 |> Bytes.toBase16 |> fromUtf8
          ⧩
          Right "0101"
runarorama commented 1 year ago

I believe this is already fixed in main:

    1 | > catch do 0xs0101 |> Bytes.toHex
          ⧩
          Right "0101"