@@ -4,6 +4,7 @@ import { markdownToHtml } from "../dist";
4
4
5
5
test ( "adds attributes to links" , async ( ) => {
6
6
const html = await markdownToHtml ( "[link](/here)" , {
7
+ allowInternalLinks : true ,
7
8
linkAttributes : { class : "someclass" } ,
8
9
} ) ;
9
10
@@ -23,6 +24,7 @@ test("adds extra attributes to external links", async () => {
23
24
24
25
test ( "doesn't add extra attributes to internal links" , async ( ) => {
25
26
const html = await markdownToHtml ( "[link](/here)" , {
27
+ allowInternalLinks : true ,
26
28
linkAttributes : { class : "someclass" } ,
27
29
externalLinkAttributes : { rel : "noopener noreferrer" } ,
28
30
} ) ;
@@ -44,6 +46,7 @@ test("adds icon to external links", async () => {
44
46
45
47
test ( "doesn't add icon to internal links" , async ( ) => {
46
48
const html = await markdownToHtml ( "[link](/here)" , {
49
+ allowInternalLinks : true ,
47
50
linkAttributes : { class : "someclass" } ,
48
51
externalLinkAttributes : { rel : "noopener noreferrer" } ,
49
52
externalLinkIconHtml : "<svg></svg>" ,
@@ -75,3 +78,33 @@ test("aborts on img tags", async () => {
75
78
76
79
expect ( html ) . toBe ( null ) ;
77
80
} ) ;
81
+
82
+ test ( "aborts on javascript: links in markdown" , async ( ) => {
83
+ const html = await markdownToHtml ( `[evil](javascript:alert(self))` , { allowInternalLinks : true } ) ;
84
+
85
+ expect ( html ) . toBe ( null ) ;
86
+ } ) ;
87
+
88
+ test ( "aborts on javascript: links in <a> tags" , async ( ) => {
89
+ const html = await markdownToHtml ( `<a href="javascript:alert('hello')">evil</a>` , { allowInternalLinks : true } ) ;
90
+
91
+ expect ( html ) . toBe ( null ) ;
92
+ } ) ;
93
+
94
+ test ( "denys internal links by default" , async ( ) => {
95
+ const html = await markdownToHtml ( "[link](/here)" , {
96
+ linkAttributes : { class : "someclass" } ,
97
+ } ) ;
98
+
99
+ expect ( html ) . toBe ( null )
100
+ } ) ;
101
+
102
+ test ( "denys internal links if requested" , async ( ) => {
103
+ const html = await markdownToHtml ( "[link](/here)" , {
104
+ allowInternalLinks : false ,
105
+ linkAttributes : { class : "someclass" } ,
106
+ } ) ;
107
+
108
+ expect ( html ) . toBe ( null )
109
+ } ) ;
110
+
0 commit comments