forked from rails/rails_xss
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FormOptionsHelper#grouped_options_for_select return a html_safe strin…
…g (and test to check that)
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'test_helper' | ||
|
||
class FormOptionsHelperTest < ActionView::TestCase | ||
|
||
Continent = Struct.new(:continent_name, :countries) | ||
Country = Struct.new(:country_id, :country_name) | ||
|
||
def test_option_groups_from_collection_for_select_returns_html_safe_string | ||
assert option_groups_from_collection_for_select(dummy_continents, "countries", "continent_name", "country_id", "country_name", "dk").html_safe? | ||
end | ||
|
||
def test_option_groups_from_collection_for_select_escapes_unsafe | ||
option_groups_from_collection_for_select_result = option_groups_from_collection_for_select(dummy_continents, "countries", "continent_name", "country_id", "country_name", "dk") | ||
assert !option_groups_from_collection_for_select_result.match(/<Africa>/) | ||
assert option_groups_from_collection_for_select_result.match(/<Africa>/) | ||
end | ||
|
||
def test_grouped_options_for_select_returns_html_safe_string | ||
assert grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]]).html_safe? | ||
end | ||
|
||
def test_grouped_options_for_select_prompt_is_escaped | ||
grouped_options_result = grouped_options_for_select(grouped_options_sample_data, 'Europe', 'Some unescaped <script>text.</script>') | ||
assert !grouped_options_result.match(/<script>/) | ||
assert grouped_options_result.match(/<script>/) | ||
end | ||
|
||
private | ||
|
||
def dummy_continents | ||
[ Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ), | ||
Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] ) ] | ||
end | ||
|
||
def grouped_options_sample_data | ||
[ ['North America', [['United States','US'],'Canada']], | ||
['Europe', ['Denmark','Germany','France']]] | ||
end | ||
|
||
end |