|
| 1 | +/* jshint scripturl:true */ |
| 2 | + |
1 | 3 | import EmberView from "ember-views/views/view"; |
2 | 4 | import run from "ember-metal/run_loop"; |
3 | 5 | import compile from "ember-template-compiler/system/compile"; |
4 | 6 | import { equalInnerHTML } from "htmlbars-test-helpers"; |
| 7 | +import { SafeString } from "ember-htmlbars/utils/string"; |
5 | 8 |
|
6 | 9 | var view; |
7 | 10 |
|
@@ -30,4 +33,48 @@ test("href is set", function() { |
30 | 33 | "attribute is output"); |
31 | 34 | }); |
32 | 35 |
|
| 36 | +test("href is sanitized when using blacklisted protocol", function() { |
| 37 | + view = EmberView.create({ |
| 38 | + context: {url: 'javascript://example.com'}, |
| 39 | + template: compile("<a href={{url}}></a>") |
| 40 | + }); |
| 41 | + appendView(view); |
| 42 | + |
| 43 | + equalInnerHTML(view.element, '<a href="unsafe:javascript://example.com"></a>', |
| 44 | + "attribute is output"); |
| 45 | +}); |
| 46 | + |
| 47 | +test("href is sanitized when using quoted non-whitelisted protocol", function() { |
| 48 | + view = EmberView.create({ |
| 49 | + context: {url: 'javascript://example.com'}, |
| 50 | + template: compile("<a href='{{url}}'></a>") |
| 51 | + }); |
| 52 | + appendView(view); |
| 53 | + |
| 54 | + equalInnerHTML(view.element, '<a href="unsafe:javascript://example.com"></a>', |
| 55 | + "attribute is output"); |
| 56 | +}); |
| 57 | + |
| 58 | +test("href is not sanitized when using non-whitelisted protocol with a SafeString", function() { |
| 59 | + view = EmberView.create({ |
| 60 | + context: {url: new SafeString('javascript://example.com')}, |
| 61 | + template: compile("<a href={{url}}></a>") |
| 62 | + }); |
| 63 | + appendView(view); |
| 64 | + |
| 65 | + equalInnerHTML(view.element, '<a href="javascript://example.com"></a>', |
| 66 | + "attribute is output"); |
| 67 | +}); |
| 68 | + |
| 69 | +test("href is sanitized when using quoted+concat non-whitelisted protocol", function() { |
| 70 | + view = EmberView.create({ |
| 71 | + context: {protocol: 'javascript:', path: '//example.com'}, |
| 72 | + template: compile("<a href='{{protocol}}{{path}}'></a>") |
| 73 | + }); |
| 74 | + appendView(view); |
| 75 | + |
| 76 | + equalInnerHTML(view.element, '<a href="unsafe:javascript://example.com"></a>', |
| 77 | + "attribute is output"); |
| 78 | +}); |
| 79 | + |
33 | 80 | } |
0 commit comments