xpath.rb fix crash when querying empty-element tag

by returning empty string.
Handling both `<test/>` and `<test></test>`
test pattern:
```
echo -e "<A>\n<B>b</B>\n<C/>\n<D></D><E>e</E></A>\n"| /var/lib/one/remotes/datastore/xpath.rb /A/B /A/C /A/D /A/E | while IFS= read -r -d '' e; do echo "'$e'"; done
```
This commit is contained in:
Anton Todorov authored and Ruben S. Montero committed 2017-07-04 18:34:22 +02:00
1 parent ae853eaebc
commit ef25a75478
1 file changed
+2 -2
+2 -2
View File
@@ -66,9 +66,9 @@ ARGV.each do |xpath|
element = xml.elements[xpath.dup]
if !element.nil?
if element.class.method_defined?(:text)
values << element.text
values << ( element.text || '' )
else
values << element.to_s
values << ( element.to_s || '' )
end
end
end