diff options
author | 2015-03-26 18:51:08 +0100 | |
---|---|---|
committer | 2015-03-26 18:51:08 +0100 | |
commit | 0862dba4f4469586560ceb09dec5b2703aec5a96 (patch) | |
tree | 84b35d320346ca67d24ca03c7c561c56cc8582e2 | |
parent | Revert "Add notice on RSS updates" (diff) | |
download | security-0862dba4f4469586560ceb09dec5b2703aec5a96.tar.gz security-0862dba4f4469586560ceb09dec5b2703aec5a96.tar.bz2 security-0862dba4f4469586560ceb09dec5b2703aec5a96.zip |
Make parsing more resilient to weird advisories
-rw-r--r-- | lib/glsav1.rb | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/glsav1.rb b/lib/glsav1.rb index 0ecea87..22ec1f1 100644 --- a/lib/glsav1.rb +++ b/lib/glsav1.rb @@ -7,9 +7,9 @@ class GLSAv1 def parse(xml) @id = xml.root['id'] - @title = xml.xpath('/glsa/title/text()').first.content - @synopsis = xml.xpath('/glsa/synopsis/text()').first.content - @product = xml.xpath('/glsa/product/text()').first.content + @title = text_content xml, '/glsa/title/text()' + @synopsis = text_content xml, '/glsa/synopsis/text()' + @product = text_content xml, '/glsa/product/text()' @date = DateTime.parse(xml.xpath('/glsa/announced/text()').first.content) @revised, @revision = xml.xpath('/glsa/revised/text()').first.content.split(': ') @@ -27,14 +27,27 @@ class GLSAv1 } end - @background = xml.xpath('/glsa/background').first.children.to_xml.strip - @description = xml.xpath('/glsa/description').first.children.to_xml.strip + @background = xml_content xml, '/glsa/background' + @description = xml_content xml, '/glsa/description' @severity = xml.xpath('/glsa/impact').first['type'] - @impact = xml.xpath('/glsa/impact').first.children.to_xml.strip - @workaround = xml.xpath('/glsa/workaround').first.children.to_xml.strip - @resolution = xml.xpath('/glsa/resolution').first.children.to_xml.strip + @impact = xml_content xml, '/glsa/impact' + @workaround = xml_content xml, '/glsa/workaround' + @resolution = xml_content xml, '/glsa/resolution' @references = xml.xpath('/glsa/references/uri').map {|uri| [uri.content, uri['link']] } self end + + private + def xml_content(xml, xpath) + xml.xpath(xpath).first.children.to_xml.strip + rescue + '' + end + + def text_content(xml, xpath) + xml.xpath(xpath).first.content + rescue + '' + end end
\ No newline at end of file |