Merge pull request #6831 from betagouv/US/fix-mon-avis-without-title
feat(MonAvisEmbedValidator): allow mon avis button without title
This commit is contained in:
commit
88c298a8c7
2 changed files with 11 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
class MonAvisEmbedValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
# We need to ensure the embed code is not any random string in order to avoid injections
|
||||
r = Regexp.new('<a href="https://monavis|voxusagers.numerique.gouv.fr/Demarches/\d+.*key=[[:alnum:]]+.*">\s*<img src="https://monavis|voxusagers.numerique.gouv.fr/(monavis-)?static/bouton-blanc|bleu.png|svg" alt="Je donne mon avis" title="Je donne mon avis sur cette démarche" />\s*</a>', Regexp::MULTILINE)
|
||||
r = Regexp.new('<a href="https://monavis|voxusagers.numerique.gouv.fr/Demarches/\d+.*key=[[:alnum:]]+.*">\s*<img src="https://monavis|voxusagers.numerique.gouv.fr/(monavis-)?static/bouton-blanc|bleu.png|svg" alt="Je donne mon avis" (title="Je donne mon avis sur cette démarche" )?/>\s*</a>', Regexp::MULTILINE)
|
||||
if record.monavis_embed.present? && !r.match?(record.monavis_embed)
|
||||
record.errors[:base] << "Le code fourni ne correspond pas au format des codes MonAvis reconnus par la plateforme."
|
||||
end
|
||||
|
|
|
@ -268,6 +268,16 @@ describe Procedure do
|
|||
let(:procedure) { build(:procedure, monavis_embed: monavis_issue_phillipe) }
|
||||
it { expect(procedure.valid?).to eq(true) }
|
||||
end
|
||||
|
||||
context 'Monavis embed code without title allowed' do
|
||||
monavis_issue_bouchra = <<-MSG
|
||||
<a href="https://voxusagers.numerique.gouv.fr/Demarches/3193?&view-mode=formulaire-avis&nd_mode=en-ligne-enti%C3%A8rement&nd_source=button&key=58e099a09c02abe629c14905ed2b055d">
|
||||
<img src="https://voxusagers.numerique.gouv.fr/static/bouton-bleu.svg" alt="Je donne mon avis" />
|
||||
</a>
|
||||
MSG
|
||||
let(:procedure) { build(:procedure, monavis_embed: monavis_issue_bouchra) }
|
||||
it { expect(procedure.valid?).to eq(true) }
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'duree de conservation' do
|
||||
|
|
Loading…
Reference in a new issue