@@ -56,11 +56,27 @@ class AttributesTest < Quickdraw::Test
5656 phlex { a ( "Href" => "javascript:alert('hello')" ) } ,
5757 phlex { a ( "Href" => "javascript:javascript:alert('hello')" ) } ,
5858 phlex { a ( href : " \t \n javascript:alert('hello')" ) } ,
59+ phlex { a ( href : "javascript:alert(1)" ) } ,
60+ phlex { a ( href : "javascript:alert(1)" ) } ,
61+ phlex { a ( href : "javascript:alert(1)" ) } ,
62+ phlex { a ( href : "javascript:alert(1)" ) } ,
63+ phlex { a ( href : "javascript:alert(1)" ) } ,
64+ phlex { a ( href : "javascript:alert(1)" ) } ,
5965 ] . each do |output |
6066 assert_equal output , %(<a></a>)
6167 end
6268 end
6369
70+ test "unsafe xlink:href attribute" do
71+ [
72+ phlex ( Phlex ::SVG ) { a ( "xlink:href" : "javascript:alert(1)" ) { "x" } } ,
73+ phlex ( Phlex ::SVG ) { a ( "xlink:href" : "javascript:alert(1)" ) { "x" } } ,
74+ phlex ( Phlex ::SVG ) { a ( "xlink:href" : "javascript:alert(1)" ) { "x" } } ,
75+ ] . each do |output |
76+ assert_equal output , %(<a>x</a>)
77+ end
78+ end
79+
6480 test "unsafe attribute name <" do
6581 error = assert_raises ( Phlex ::ArgumentError ) do
6682 phlex { div ( "<" => true ) }
@@ -101,6 +117,38 @@ class AttributesTest < Quickdraw::Test
101117 assert_equal error . message , "Unsafe attribute name detected: \" ."
102118 end
103119
120+ test "unsafe attribute name with space (String)" do
121+ error = assert_raises ( Phlex ::ArgumentError ) do
122+ phlex { div ( "foo bar" => true ) }
123+ end
124+
125+ assert_equal error . message , "Unsafe attribute name detected: foo bar."
126+ end
127+
128+ test "unsafe attribute name with space (Symbol)" do
129+ error = assert_raises ( Phlex ::ArgumentError ) do
130+ phlex { div ( "foo bar" : true ) }
131+ end
132+
133+ assert_equal error . message , "Unsafe attribute name detected: foo bar."
134+ end
135+
136+ test "unsafe attribute name with slash (String)" do
137+ error = assert_raises ( Phlex ::ArgumentError ) do
138+ phlex { div ( "foo/bar" => true ) }
139+ end
140+
141+ assert_equal error . message , "Unsafe attribute name detected: foo/bar."
142+ end
143+
144+ test "unsafe attribute name with slash (Symbol)" do
145+ error = assert_raises ( Phlex ::ArgumentError ) do
146+ phlex { div ( "foo/bar" : true ) }
147+ end
148+
149+ assert_equal error . message , "Unsafe attribute name detected: foo/bar."
150+ end
151+
104152 test "_, nil" do
105153 output = phlex { div ( attribute : nil ) }
106154 assert_equal output , %(<div></div>)
0 commit comments