X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fweb%2Fxml%2Fxml.ex;h=b3ccf4a55b072bf7834c1679473c1e5c36420aec;hb=816db3f494c6fcc60d0a700dfc473a9cc49c84a0;hp=22faf72df4cb5934e3e7bc667b4751f3bbca4a15;hpb=d1dce56a85e041f78e1d50900a0c9591610de2b9;p=akkoma diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex index 22faf72df..b3ccf4a55 100644 --- a/lib/pleroma/web/xml/xml.ex +++ b/lib/pleroma/web/xml/xml.ex @@ -1,19 +1,41 @@ defmodule Pleroma.Web.XML do + require Logger + + def string_from_xpath(_, :error), do: nil + def string_from_xpath(xpath, doc) do - {:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc) + try do + {:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc) - res = res - |> to_string - |> String.trim + res = + res + |> to_string + |> String.trim() - if res == "", do: nil, else: res + if res == "", do: nil, else: res + catch + _e -> + Logger.debug("Couldn't find xpath #{xpath} in XML doc") + nil + end end def parse_document(text) do - {doc, _rest} = text - |> :binary.bin_to_list - |> :xmerl_scan.string + try do + {doc, _rest} = + text + |> :binary.bin_to_list() + |> :xmerl_scan.string(quiet: true) - doc + doc + rescue + _e -> + Logger.debug("Couldn't parse XML: #{inspect(text)}") + :error + catch + :exit, _error -> + Logger.debug("Couldn't parse XML: #{inspect(text)}") + :error + end end end