template-utils.test.js 886 B

1234567891011121314151617181920212223242526272829
  1. import {safeURI} from "content-src/asrouter/template-utils";
  2. describe("safeURI", () => {
  3. let warnStub;
  4. beforeEach(() => {
  5. warnStub = sinon.stub(console, "warn");
  6. });
  7. afterEach(() => {
  8. warnStub.restore();
  9. });
  10. it("should allow http: URIs", () => {
  11. assert.equal(safeURI("http://foo.com"), "http://foo.com");
  12. });
  13. it("should allow https: URIs", () => {
  14. assert.equal(safeURI("https://foo.com"), "https://foo.com");
  15. });
  16. it("should allow data URIs", () => {
  17. assert.equal(safeURI("data:image/png;base64,iVBO"), "data:image/png;base64,iVBO");
  18. });
  19. it("should not allow javascript: URIs", () => {
  20. assert.equal(safeURI("javascript:foo()"), ""); // eslint-disable-line no-script-url
  21. assert.calledOnce(warnStub);
  22. });
  23. it("should not warn if the URL is falsey ", () => {
  24. assert.equal(safeURI(), "");
  25. assert.notCalled(warnStub);
  26. });
  27. });