aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-06-24 14:35:32 +0200
committerRoger Braun <roger@rogerbraun.net>2017-06-24 14:35:32 +0200
commit39bacba2803260a21dc1c50ba90695baa25193b3 (patch)
treea82a6fbc0e197bec67f46bfaf2d1675ede2f7ba3 /lib
parent6935fc3e010391d647bcec70bd3d6d6cb8de73a0 (diff)
downloadpleroma-39bacba2803260a21dc1c50ba90695baa25193b3.tar.gz
More resilient xml parsing.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/ostatus/ostatus.ex1
-rw-r--r--lib/pleroma/web/web_finger/web_finger.ex2
-rw-r--r--lib/pleroma/web/xml/xml.ex17
3 files changed, 15 insertions, 5 deletions
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index bb0a3b5b9..f987752a0 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -30,6 +30,7 @@ defmodule Pleroma.Web.OStatus do
activities = Enum.map(entries, fn (entry) ->
{:xmlObj, :string, object_type} = :xmerl_xpath.string('string(/entry/activity:object-type[1])', entry)
{:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
+ Logger.debug("Handling #{verb}")
case verb do
'http://activitystrea.ms/schema/1.0/follow' ->
diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex
index e8b738c96..7ae413c26 100644
--- a/lib/pleroma/web/web_finger/web_finger.ex
+++ b/lib/pleroma/web/web_finger/web_finger.ex
@@ -98,7 +98,7 @@ defmodule Pleroma.Web.WebFinger do
end
with {:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- response,
- doc <- XML.parse_document(body),
+ doc when doc != :error<- XML.parse_document(body),
{:ok, data} <- webfinger_from_xml(doc) do
{:ok, data}
else
diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex
index 22faf72df..63580c1f8 100644
--- a/lib/pleroma/web/xml/xml.ex
+++ b/lib/pleroma/web/xml/xml.ex
@@ -1,4 +1,7 @@
defmodule Pleroma.Web.XML do
+ require Logger
+
+ def string_from_xpath(xpath, :error), do: nil
def string_from_xpath(xpath, doc) do
{:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc)
@@ -10,10 +13,16 @@ defmodule Pleroma.Web.XML do
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
- doc
+ doc
+ catch
+ :exit, error ->
+ Logger.debug("Couldn't parse xml: #{inspect(text)}")
+ :error
+ end
end
end