Navigation Link: fix regex to allow multiline SVG (#14481)

* Fix regex to check svg. Fixes #14334

* Add tests
This commit is contained in:
Siddharth 2021-08-13 12:16:04 +05:30 committed by GitHub
parent f0093c5338
commit c5c484408e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -1,5 +1,5 @@
class NavigationLink < ApplicationRecord
SVG_REGEXP = /<svg .*>/i.freeze
SVG_REGEXP = /<svg .*>/im.freeze
before_validation :allow_relative_url, if: :url?
before_save :strip_local_hostname, if: :url?

View file

@ -13,6 +13,12 @@ RSpec.describe NavigationLink, type: :model do
it "validates the icon" do
navigation_link.icon = "test.png"
expect(navigation_link).not_to be_valid
navigation_link.icon = "<svg foo='bar'>"
expect(navigation_link).to be_valid
navigation_link.icon = "<svg foo='bar'\nbaz='lol'\n\n more stuff...\n\n. >"
expect(navigation_link).to be_valid
end
context "when validating the URL" do