Skip to content

Commit 9f862be

Browse files
committed
Filter out unknown keyword lists' keys in IEx.Options
1 parent d2c5fa3 commit 9f862be

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/iex/lib/iex.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ defmodule IEx do
151151
Registers options used on inspect.
152152
"""
153153
def inspect_opts(opts) when is_list(opts) do
154-
# FIXME: validate keys before setting
155-
:application.set_env(:iex, :inspect_opts, Keyword.merge(inspect_opts, opts))
154+
old_opts = inspect_opts()
155+
filtered_opts = Enum.filter opts, fn {name, _} ->
156+
name in old_opts
157+
end
158+
:application.set_env(:iex, :inspect_opts, Keyword.merge(old_opts, filtered_opts))
156159
end
157160

158161
@doc """

lib/iex/lib/iex/options.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ defmodule IEx.Options do
123123

124124
def set(:colors, colors) when is_list(colors) do
125125
{ :ok, old_colors } = :application.get_env(:iex, :colors)
126-
# FIXME: validate keys before setting
127-
:application.set_env(:iex, :colors, Keyword.merge(old_colors, colors))
126+
# Validate keys before setting
127+
filtered_colors = Enum.filter colors, fn {name, _} ->
128+
name in old_colors
129+
end
130+
:application.set_env(:iex, :colors, Keyword.merge(old_colors, filtered_colors))
128131
old_colors
129132
end
130133

@@ -134,7 +137,7 @@ defmodule IEx.Options do
134137

135138
def set(:inspect, opts) when is_list(opts) do
136139
old_opts = IEx.inspect_opts
137-
# FIXME: validate keys before setting
140+
# `opts` are validated by IEx.inspect_opts
138141
IEx.inspect_opts(opts)
139142
old_opts
140143
end

0 commit comments

Comments
 (0)