Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
bf9d3d4a
Commit
bf9d3d4a
authored
Apr 03, 2018
by
kaniini
Browse files
XML: use try/catch with XPath functions
parent
bf953989
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/xml/xml.ex
View file @
bf9d3d4a
...
...
@@ -4,14 +4,20 @@ defmodule Pleroma.Web.XML do
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment