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:
Filipe
2024-05-30 14:07:20 +02:00
committed by GitHub
2 changed files with 22 additions and 0 deletions

View File

@@ -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

View File

@@ -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