Sanitizing descriptions before saving a record has a few drawbacks: 1. It makes the application rely on data being safe in the database. If somehow dangerous data enters the database, the application will be vulnerable to XSS attacks 2. It makes the code complicated 3. It isn't backwards compatible; if we decide to disallow a certain HTML tag in the future, we'd need to sanitize existing data. On the other hand, sanitizing the data in the view means we don't need to triple-check dangerous HTML has already been stripped when we see the method `auto_link_already_sanitized_html`, since now every time we use it we sanitize the text in the same line we call this method. We could also sanitize the data twice, both when saving to the database and when displaying values in the view. However, doing so wouldn't make the application safer, since we sanitize text introduced through textarea fields but we don't sanitize text introduced through input fields. Finally, we could also overwrite the `description` method so it sanitizes the text. But we're already introducing Globalize which overwrites that method, and overwriting it again is a bit too confusing in my humble opinion. It can also lead to hard-to-debug behaviour.
20 lines
459 B
Ruby
20 lines
459 B
Ruby
shared_examples "sanitizable" do
|
|
let(:sanitizable) { build(model_name(described_class)) }
|
|
|
|
describe "#tag_list" do
|
|
before do
|
|
unless described_class.included_modules.include?(Taggable)
|
|
skip "#{described_class} does not have a tag list"
|
|
end
|
|
end
|
|
|
|
it "sanitizes the tag list" do
|
|
sanitizable.tag_list = "user_id=1"
|
|
|
|
sanitizable.valid?
|
|
|
|
expect(sanitizable.tag_list).to eq(["user_id1"])
|
|
end
|
|
end
|
|
end
|