mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Merge pull request #12506 from anansilva/12448-sanitise-html-enterprise-group
Sanitise HTML in long description of enterprise group [read-only]
This commit is contained in:
@@ -74,6 +74,16 @@ class EnterpriseGroup < ApplicationRecord
|
||||
permalink
|
||||
end
|
||||
|
||||
# Remove any unsupported HTML.
|
||||
def long_description
|
||||
HtmlSanitizer.sanitize(super)
|
||||
end
|
||||
|
||||
# Remove any unsupported HTML.
|
||||
def long_description=(html)
|
||||
super(HtmlSanitizer.sanitize(html))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sanitize_permalink
|
||||
|
||||
@@ -118,4 +118,16 @@ RSpec.describe EnterpriseGroup do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "serialisation" do
|
||||
it "sanitises HTML in long_description" do
|
||||
subject.long_description = "Hello <script>alert</script> dearest <b>monster</b>."
|
||||
expect(subject.long_description).to eq "Hello alert dearest <b>monster</b>."
|
||||
end
|
||||
|
||||
it "sanitises existing HTML in long_description" do
|
||||
subject[:long_description] = "Hello <script>alert</script> dearest <b>monster</b>."
|
||||
expect(subject.long_description).to eq "Hello alert dearest <b>monster</b>."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user