|
45 | 45 | phlex { a("Href" => "javascript:alert('hello')") }, |
46 | 46 | phlex { a("Href" => "javascript:javascript:alert('hello')") }, |
47 | 47 | phlex { a(href: " \t\njavascript:alert('hello')") }, |
| 48 | + phlex { a(href: "javascript:alert(1)") }, |
| 49 | + phlex { a(href: "javascript:alert(1)") }, |
| 50 | + phlex { a(href: "javascript:alert(1)") }, |
| 51 | + phlex { a(href: "javascript:alert(1)") }, |
| 52 | + phlex { a(href: "javascript:alert(1)") }, |
| 53 | + phlex { a(href: "javascript:alert(1)") }, |
48 | 54 | ].each do |output| |
49 | 55 | assert_equal_html output, %(<a></a>) |
50 | 56 | end |
51 | 57 | end |
52 | 58 |
|
| 59 | +test "unsafe xlink:href attribute" do |
| 60 | + [ |
| 61 | + phlex(Phlex::SVG) { a("xlink:href": "javascript:alert(1)") { "x" } }, |
| 62 | + phlex(Phlex::SVG) { a("xlink:href": "javascript:alert(1)") { "x" } }, |
| 63 | + phlex(Phlex::SVG) { a("xlink:href": "javascript:alert(1)") { "x" } }, |
| 64 | + ].each do |output| |
| 65 | + assert_equal_html output, %(<a>x</a>) |
| 66 | + end |
| 67 | +end |
| 68 | + |
53 | 69 | test "unsafe attribute name <" do |
54 | 70 | error = assert_raises(Phlex::ArgumentError) do |
55 | 71 | phlex { div("<" => true) } |
|
90 | 106 | assert_equal error.message, "Unsafe attribute name detected: \"." |
91 | 107 | end |
92 | 108 |
|
| 109 | +test "unsafe attribute name with space (String)" do |
| 110 | + error = assert_raises(Phlex::ArgumentError) do |
| 111 | + phlex { div("foo bar" => true) } |
| 112 | + end |
| 113 | + |
| 114 | + assert_equal error.message, "Unsafe attribute name detected: foo bar." |
| 115 | +end |
| 116 | + |
| 117 | +test "unsafe attribute name with space (Symbol)" do |
| 118 | + error = assert_raises(Phlex::ArgumentError) do |
| 119 | + phlex { div("foo bar": true) } |
| 120 | + end |
| 121 | + |
| 122 | + assert_equal error.message, "Unsafe attribute name detected: foo bar." |
| 123 | +end |
| 124 | + |
| 125 | +test "unsafe attribute name with slash (String)" do |
| 126 | + error = assert_raises(Phlex::ArgumentError) do |
| 127 | + phlex { div("foo/bar" => true) } |
| 128 | + end |
| 129 | + |
| 130 | + assert_equal error.message, "Unsafe attribute name detected: foo/bar." |
| 131 | +end |
| 132 | + |
| 133 | +test "unsafe attribute name with slash (Symbol)" do |
| 134 | + error = assert_raises(Phlex::ArgumentError) do |
| 135 | + phlex { div("foo/bar": true) } |
| 136 | + end |
| 137 | + |
| 138 | + assert_equal error.message, "Unsafe attribute name detected: foo/bar." |
| 139 | +end |
| 140 | + |
93 | 141 | test "_, nil" do |
94 | 142 | output = phlex { div(attribute: nil) } |
95 | 143 | assert_equal_html output, %(<div></div>) |
|
0 commit comments