Guard against error extracting `body` from URL (#20428)

If `Nokogiri::HTML(value).at_xpath('//body')` fails to find the `body` element, it will return `nil`. We can guard against that with an early return. Avoids calling `children` on `Nilclass` in those cases.
This commit is contained in:
Emily Strickland 2022-11-11 12:22:28 -08:00 committed by GitHub
parent 31005aad12
commit 96f51e593f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -76,6 +76,7 @@ class Account::Field < ActiveModelSerializers::Model
def extract_url_from_html def extract_url_from_html
doc = Nokogiri::HTML(value).at_xpath('//body') doc = Nokogiri::HTML(value).at_xpath('//body')
return if doc.nil?
return if doc.children.size > 1 return if doc.children.size > 1
element = doc.children.first element = doc.children.first