mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:02:46 +08:00
FIX: Error when an invalid date is passed to certificate generator.
https://meta.discourse.org/t/broken-image-in-discobot-certificate-with-no-logo-small-url/76594/2
This commit is contained in:
parent
6f89db4c24
commit
ee1b90503c
|
@ -2,7 +2,19 @@ module DiscourseNarrativeBot
|
|||
class CertificateGenerator
|
||||
def initialize(user, date)
|
||||
@user = user
|
||||
@date = I18n.l(Date.parse(date), format: :date_only)
|
||||
|
||||
date =
|
||||
begin
|
||||
Date.parse(date)
|
||||
rescue ArgumentError => e
|
||||
if e.message == 'invalid date'
|
||||
Date.parse(Date.today.to_s)
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
@date = I18n.l(date, format: :date_only)
|
||||
@discobot_user = User.find(-2)
|
||||
end
|
||||
|
||||
|
|
|
@ -33,18 +33,5 @@ describe "Discobot Certificate" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when date is invalid' do
|
||||
it 'should raise the right error' do
|
||||
expect do
|
||||
get '/discobot/certificate.svg', params: {
|
||||
name: user.name,
|
||||
date: "<script type=\"text/javascript\">alert('This app is probably vulnerable to XSS attacks!');</script>",
|
||||
avatar_url: 'https://somesite.com/someavatar',
|
||||
user_id: user.id
|
||||
}
|
||||
end.to raise_error(ArgumentError, 'invalid date')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseNarrativeBot::CertificateGenerator do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
describe 'when an invalid date is given' do
|
||||
it 'should default to the current date' do
|
||||
expect { described_class.new(user, "2017-00-10") }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user