Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed style gauntlet regex to allow for negative values such as margin:-18px #227

Merged
merged 2 commits into from Nov 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions spec/lib/sanitize_spec.rb
Expand Up @@ -74,6 +74,13 @@
res.should match(/width/)
end

it "should allow negative values" do
str = "<div style='margin: -18px;height: 10px;'></div>"
res = Sanitize.clean(str, Instructure::SanitizeField::SANITIZE)
res.should match(/margin/)
res.should match(/height/)
end

it "should remove non-whitelisted css attributes" do
str = "<div style='bacon: 5px; border-left-color: #fff;'></div>"
res = Sanitize.clean(str, Instructure::SanitizeField::SANITIZE)
Expand Down
2 changes: 1 addition & 1 deletion vendor/plugins/sanitize_field/lib/sanitize_field.rb
Expand Up @@ -34,7 +34,7 @@ def self.sanitize_style(env)
style = node['style'] || ""
# taken from https://github.com/flavorjones/loofah/blob/master/lib/loofah/html5/scrub.rb
# the gauntlet
style = '' unless style =~ /\A([:,\;#%.\(\)\/\sa-zA-Z0-9!]|\w-\w|\'[\s\w]+\'|\"[\s\w]+\"|\([\d,\s]+\))*\z/
style = '' unless style =~ /\A([-:,\;#%.\(\)\/\sa-zA-Z0-9!]|\w-\w|\'[\s\w]+\'|\"[\s\w]+\"|\([\d,\s]+\))*\z/
style = '' unless style =~ /\A\s*([-\w]+\s*:[^\;]*(\;\s*|$))*\z/

config = env[:config]
Expand Down