File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -401,9 +401,16 @@ def __attributes__(attributes, buffer = +"")
401401 unless Phlex ::SGML ::SafeObject === v
402402 normalized_name = lower_name . delete ( "^a-z-" )
403403
404- if value != true && REF_ATTRIBUTES . include? ( normalized_name ) && value . downcase . delete ( "^a-z:" ) . start_with? ( "javascript:" )
405- # We just ignore these because they were likely not specified by the developer.
406- next
404+ if value != true && REF_ATTRIBUTES . include? ( normalized_name )
405+ case value
406+ when String
407+ if value . downcase . delete ( "^a-z:" ) . start_with? ( "javascript:" )
408+ # We just ignore these because they were likely not specified by the developer.
409+ next
410+ end
411+ else
412+ raise Phlex ::ArgumentError . new ( "Invalid attribute value for #{ k } : #{ v . inspect } ." )
413+ end
407414 end
408415
409416 if normalized_name . bytesize > 2 && normalized_name . start_with? ( "on" ) && !normalized_name . include? ( "-" )
Original file line number Diff line number Diff line change 2626 end
2727end
2828
29+ test "href with hash" do
30+ expect {
31+ phlex { a ( href : { } ) }
32+ } . to_raise ( Phlex ::ArgumentError ) do |error |
33+ expect ( error . message ) == "Invalid attribute value for href: #{ { } . inspect } ."
34+ end
35+ end
36+
2937test "unsafe href attribute" do
3038 expect (
3139 phlex { div ( href : "javascript:alert('hello')" ) } ,
You can’t perform that action at this time.
0 commit comments