marked.spec.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*eslint no-script-url:0*/
  2. import marked from 'app/utils/marked';
  3. function expectMarkdown(test) {
  4. expect(marked(test[0])).toEqual('<p>' + test[1] + '</p>\n');
  5. }
  6. describe('marked', function() {
  7. it('normal links get rendered as html', function() {
  8. for (const test of [
  9. ['[x](http://example.com)', '<a href="http://example.com">x</a>'],
  10. ['[x](https://example.com)', '<a href="https://example.com">x</a>'],
  11. ['[x](mailto:foo@example.com)', '<a href="mailto:foo@example.com">x</a>'],
  12. ]) {
  13. expectMarkdown(test);
  14. }
  15. });
  16. it('rejected links should be rendered as plain text', function() {
  17. for (const test of [
  18. ['[x](javascript:foo)', 'javascript:foo'],
  19. ['[x](java\nscript:foo)', '[x](java\nscript:foo)'],
  20. ['[x](data:foo)', 'data:foo'],
  21. ['[x](vbscript:foo)', 'vbscript:foo'],
  22. ]) {
  23. expectMarkdown(test);
  24. }
  25. });
  26. it('normal images get rendered as html', function() {
  27. for (const test of [
  28. ['![](http://example.com)', '<img src="http://example.com" alt="">'],
  29. ['![x](http://example.com)', '<img src="http://example.com" alt="x">'],
  30. ['![x](https://example.com)', '<img src="https://example.com" alt="x">'],
  31. ]) {
  32. expectMarkdown(test);
  33. }
  34. });
  35. it("rejected images shouldn't be rendered at all", function() {
  36. for (const test of [['![x](javascript:foo)', '']]) {
  37. expectMarkdown(test);
  38. }
  39. });
  40. });