Skip to content

Commit 0edf4d2

Browse files
committed
Fail fast if StringIO receives a file operation
1 parent 9d5af3f commit 0edf4d2

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/elixir/lib/string_io.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ defmodule StringIO do
188188
{:noreply, state}
189189
end
190190

191+
# Fail fast if someone tries to use it with a File API
192+
def handle_info({:file_request, from, reply_as, _req}, state) do
193+
send(from, {:file_reply, reply_as, {:error, :enotsup}})
194+
{:noreply, state}
195+
end
196+
191197
def handle_info({:DOWN, _, _, _, _}, state) do
192198
{:stop, :shutdown, state}
193199
end

lib/elixir/test/elixir/string_io_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,9 @@ defmodule StringIOTest do
392392
assert result == {:ok, [{:integer, 1, 1}, {:dot, 1}], 1}
393393
assert StringIO.contents(pid) == {"", "p>p>"}
394394
end
395+
396+
test "returns enotsup for files" do
397+
{:ok, pid} = StringIO.open("123")
398+
assert :file.position(pid, :cur) == {:error, :enotsup}
399+
end
395400
end

0 commit comments

Comments
 (0)