diff options
author | Emily Strickland <github@emily.st> | 2022-11-11 12:22:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 21:22:28 +0100 |
commit | 96f51e593f2609579b8155d971bcbc5ab9e7cd4c (patch) | |
tree | 17084096e68d03234d20a0ac0fc70cab5323ece2 | |
parent | 31005aad12c6a915a00501765a6dab25878326cb (diff) |
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.
-rw-r--r-- | app/models/account/field.rb | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/app/models/account/field.rb b/app/models/account/field.rb index e84a0eeb1..ffc8dce80 100644 --- a/app/models/account/field.rb +++ b/app/models/account/field.rb @@ -76,6 +76,7 @@ class Account::Field < ActiveModelSerializers::Model def extract_url_from_html doc = Nokogiri::HTML(value).at_xpath('//body') + return if doc.nil? return if doc.children.size > 1 element = doc.children.first |