Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/cherry_picks_from_master' into 2…
…-0-stable
- Loading branch information
Showing
12 changed files
with
167 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,20 @@ | ||
module Refinery | ||
module PagesHelper | ||
|
||
def sanitize_hash(input_hash) | ||
sanitized_hash = HashWithIndifferentAccess.new | ||
input_hash.each do |key, value| | ||
# ActionPack's sanitize calls html_safe on sanitized input. | ||
sanitized_hash[key] = if value.respond_to? :html_safe | ||
sanitize value | ||
elsif value.respond_to? :each | ||
sanitize_hash value | ||
else | ||
value | ||
end | ||
end | ||
sanitized_hash | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
module Refinery | ||
describe PagesHelper do | ||
describe "#sanitize_hash" do | ||
context "when hash value responds to html_safe" do | ||
it "returns hash with sanitized values" do | ||
hash = { :key => "hack<script>" } | ||
helper.sanitize_hash(hash).should eq("key" => "hack") | ||
end | ||
end | ||
|
||
context "when hash value is an array" do | ||
it "returns hash with sanitized values" do | ||
hash = { :key => { :x => "hack<script>", :y => "malware<script>" } } | ||
helper.sanitize_hash(hash).should eq("key"=>{"x"=>"hack", "y"=>"malware"}) | ||
end | ||
end | ||
|
||
context "when string value doesn't repsond to html_safe" do | ||
it "returns hash with value untouched" do | ||
String.any_instance.stub(:respond_to?).and_return(false) | ||
|
||
hash = { :key => "hack<script>" } | ||
helper.sanitize_hash(hash).should eq("key"=>"hack<script>") | ||
end | ||
end | ||
end | ||
end | ||
end |