Skip to content

Commit

Permalink
Don't discard the user supplied {:rules, _, _, _} when we don't use…
Browse files Browse the repository at this point in the history
… one ourselve.
  • Loading branch information
Shakadak committed Apr 6, 2022
1 parent 377e92e commit 2e7a53e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Changed

* Handling the option `{:rules, _}` ourselve, as wall as partially the option `{:rules, _, _, _}`.
* Handling the option `{:rules, _}` ourselve, as well as partially the option `{:rules, _, _, _}`.
When nothing is given, a new table is created, and destroyed after.
If a table is given, and a DTD option is chosen, the table is reused for the DTD handling.
If a custom `{:rules, _, _, _}` is given, and a restrictive DTD option is chosen, the custome rule will be overriden.
Expand Down
13 changes: 7 additions & 6 deletions lib/sweet_xml.ex
Original file line number Diff line number Diff line change
Expand Up @@ -508,17 +508,18 @@ defmodule SweetXml do
opts = rules ++ opts ++ SweetXml.Options.handle_dtd(dtd_arg).(ets)
{opts, :not_ours}

{[[{:rules, _read_fun, _write_fun, _ets}]], opts} ->
{[[{:rules, _read_fun, _write_fun, _ets}] = rules], opts} ->
ets = :ets.new(nil, [:public])
dtd_opts = SweetXml.Options.handle_dtd(dtd_arg).(ets)
_ = case :proplists.split(dtd_opts, [:rules]) do
{[], _opts} -> :ok
{[_], _opts} ->
# If we don't use the `:rules` option for the DTDs, then we can keep the original one
extra_opts = case :proplists.split(dtd_opts, [:rules]) do
{[], _opts} -> rules
{[[{:rules, _, _, _}] = extra], _opts} ->
require Logger
_ = Logger.warn("rules opt will be overriden because of the dtd option")
:warned
extra
end
{opts ++ dtd_opts, {:cleanup, ets}}
{opts ++ dtd_opts ++ extra_opts, {:cleanup, ets}}
end

pid = spawn_link fn -> :xmerl_scan.string('', opts ++ continuation_opts(doc, waiter)) end
Expand Down

0 comments on commit 2e7a53e

Please sign in to comment.