mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 05:25:41 +08:00
FIX: don't error Topic#similar_to when prepared raw is blank (#10711)
If raw contains incorrect URL, `prepare_data` returns empty string: https://github.com/discourse/discourse/blob/master/lib/search.rb#L91 Therefore we should not only check if the cooked post is not blank but also if prepared data is not blank.
This commit is contained in:
parent
5a832265a3
commit
c934a0f759
@ -597,9 +597,11 @@ class Topic < ActiveRecord::Base
|
|||||||
PrettyText.cook(raw[0...MAX_SIMILAR_BODY_LENGTH].strip)
|
PrettyText.cook(raw[0...MAX_SIMILAR_BODY_LENGTH].strip)
|
||||||
)
|
)
|
||||||
|
|
||||||
if cooked.present?
|
prepared_data = cooked.present? && Search.prepare_data(cooked)
|
||||||
|
|
||||||
|
if prepared_data.present?
|
||||||
raw_tsquery = Search.set_tsquery_weight_filter(
|
raw_tsquery = Search.set_tsquery_weight_filter(
|
||||||
Search.prepare_data(cooked),
|
prepared_data,
|
||||||
'B'
|
'B'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -519,6 +519,10 @@ describe Topic do
|
|||||||
expect(Topic.similar_to('some title', '#')).to eq([])
|
expect(Topic.similar_to('some title', '#')).to eq([])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not result in invalid statement when prepared data is blank' do
|
||||||
|
expect(Topic.similar_to('some title', 'https://discourse.org/#INCORRECT#URI')).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
context 'with a similar topic' do
|
context 'with a similar topic' do
|
||||||
fab!(:post) {
|
fab!(:post) {
|
||||||
SearchIndexer.enable
|
SearchIndexer.enable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user