lpil / envoy

📂 A zero dependency cross platform Gleam package for reading environment variables
13 stars 0 forks source link

Env vars with Unicode characters cause exception #1

Closed tmbrwn closed 3 months ago

tmbrwn commented 3 months ago

Hello!

I'm having trouble with Unicode characters in my environment variables.

Steps to Reproduce

vars.gleam

import gleam/io
import envoy

pub fn main() {
  io.debug(envoy.get("TEST"))
}

Shell

$ TEST="$(echo "\u100")" gleam run
   Compiled in 0.01s
    Running vars.main
exception error: bad argument
  in function  list_to_binary/1
     called as list_to_binary([256])
     *** argument 1: not an iolist term
  in call from envoy_ffi:get/1 (/Users/tim/Projects/sandbox/gleam/vars/build/dev/erlang/envoy/_gleam_artefacts/envoy_ffi.erl, line 8)
  in call from vars:main/0 (/Users/tim/Projects/sandbox/gleam/vars/build/dev/erlang/vars/_gleam_artefacts/vars.erl, line 8)

Notes

If running bash version <4.2 before \u was supported, you can use TEST="$(printf '\xc4\x80')" gleam run to get an environment variable with value \u100.

This problem occurs with any characters with value >255. I'm not familiar with the Erlang stdlib, but from looking around a bit it seems that os:getenv doesn't always return something that can be considered an iolist, presumably because the character code points don't fit into a single byte. I'm not sure what the output needs to be wrapped in to properly transform the string returned by os:getenv to the Gleam String returned by get, but please let me know if I can be of any assistance!

Loving Gleam, btw! Thanks a bunch!

lpil commented 3 months ago

Thank you! Sorry for the bug, and thank you for your support! 💜