bcpeinhardt / simplifile

Simple file operations for Gleam that work on all targets (Erlang/Node/Deno)
68 stars 10 forks source link

`simplifile.read_directory` throws an exception when a filename contains certain characters #25

Closed buzugu closed 3 months ago

buzugu commented 3 months ago

Good morning!

Hopefully these repro steps work for someone else. System is macOS 14.3.1, Intel chip.

gleam new simplifile_crash
cd simplifile_crash
gleam add simplifile
echo "import simplifile\npub fn main() { simplifile.read_directory(\".\") }" > src/simplifile_crash.gleam
gleam run # works fine
touch "uh oh’"
gleam run # runtime exception

Here's the exception in question:

exception error: bad argument
  in function  list_to_binary/1
     called as list_to_binary([117,104,32,111,104,8217])
     *** argument 1: not an iolist term
  in call from simplifile_erl:'-list_directory/1-lc$^0/1-0-'/1 (/private/tmp/simplifile_crash/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_erl.erl, line 102)
  in call from simplifile_erl:'-list_directory/1-lc$^0/1-0-'/1 (/private/tmp/simplifile_crash/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_erl.erl, line 102)
  in call from simplifile_erl:list_directory/1 (/private/tmp/simplifile_crash/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_erl.erl, line 102)
  in call from simplifile:read_directory/1 (/private/tmp/simplifile_crash/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.erl, line 255)

Have a lovely day. :)

bcpeinhardt commented 3 months ago

Sorry that took a minute! Suffering from an RSI so had to fix one-handed haha. Try updating to 1.5.1, seems like I wasn't ensuring filenames were properly utf8 encoded in my erlang ffi for read_directory, should work now.

buzugu commented 3 months ago

Indeed it does! Thank you :) no need to apologize for labor you don't owe me.