FIX: InlineOneboxer watched word censor error (#16921)

In 7328a2bfb0 we changed the
InlineOneboxer#onebox_for method to run the title of the
onebox through WatchedWord#censor_text. However, it is
allowable for the title to be nil, which was causing this
error in production:

> NoMethodError : undefined method gsub for nil:NilClass

We just need to check whether the title is nil before trying
to censor it.
This commit is contained in:
Martin Brennan
2022-05-26 14:01:44 +10:00
committed by GitHub
parent 037436047d
commit 61b9e3ee30
3 changed files with 33 additions and 9 deletions

View File

@@ -107,8 +107,14 @@ class InlineOneboxer
)
end
end
onebox = { url: url, title: title && Emoji.gsub_emoji_to_unicode(title) }
onebox[:title] = WordWatcher.censor_text(onebox[:title])
title = title && Emoji.gsub_emoji_to_unicode(title)
if title.present?
title = WordWatcher.censor_text(title)
end
onebox = { url: url, title: title }
Discourse.cache.write(cache_key(url), onebox, expires_in: 1.day) if !opts[:skip_cache]
onebox
end