mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FIX: prevents exception when text input is nil (#12922)
nil was converted to "" and the matching regex would return [] and then be converted to nil with max usage. Example exception: ``` NoMethodError (undefined method `<=' for nil:NilClass) lib/text_sentinel.rb:71:in `seems_unpretentious?' lib/validators/quality_title_validator.rb:13:in `validate_each' lib/topic_creator.rb:25:in `valid?' ```
This commit is contained in:
@ -61,6 +61,18 @@ describe TextSentinel do
|
||||
end
|
||||
end
|
||||
|
||||
it "uses a sensible min entropy value when min body length is less than min entropy" do
|
||||
SiteSetting.min_post_length = 3
|
||||
SiteSetting.body_min_entropy = 7
|
||||
expect(TextSentinel.body_sentinel('Yup')).to be_valid
|
||||
end
|
||||
|
||||
it "uses a sensible min entropy value when min pm body length is less than min entropy" do
|
||||
SiteSetting.min_post_length = 5
|
||||
SiteSetting.min_personal_message_post_length = 3
|
||||
SiteSetting.body_min_entropy = 7
|
||||
expect(TextSentinel.body_sentinel('Lol', private_message: true)).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "validity" do
|
||||
@ -144,19 +156,9 @@ describe TextSentinel do
|
||||
|
||||
end
|
||||
|
||||
context 'body_sentinel' do
|
||||
|
||||
it "uses a sensible min entropy value when min body length is less than min entropy" do
|
||||
SiteSetting.min_post_length = 3
|
||||
SiteSetting.body_min_entropy = 7
|
||||
expect(TextSentinel.body_sentinel('Yup')).to be_valid
|
||||
end
|
||||
|
||||
it "uses a sensible min entropy value when min pm body length is less than min entropy" do
|
||||
SiteSetting.min_post_length = 5
|
||||
SiteSetting.min_personal_message_post_length = 3
|
||||
SiteSetting.body_min_entropy = 7
|
||||
expect(TextSentinel.body_sentinel('Lol', private_message: true)).to be_valid
|
||||
context 'seems_unpretentious?' do
|
||||
it 'works with nil title' do
|
||||
expect(TextSentinel.title_sentinel(nil).seems_unpretentious?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user