@@ -4,6 +4,7 @@ import { markdownToHtml } from "../dist";
44
55test ( "adds attributes to links" , async ( ) => {
66 const html = await markdownToHtml ( "[link](/here)" , {
7+ allowInternalLinks : true ,
78 linkAttributes : { class : "someclass" } ,
89 } ) ;
910
@@ -23,6 +24,7 @@ test("adds extra attributes to external links", async () => {
2324
2425test ( "doesn't add extra attributes to internal links" , async ( ) => {
2526 const html = await markdownToHtml ( "[link](/here)" , {
27+ allowInternalLinks : true ,
2628 linkAttributes : { class : "someclass" } ,
2729 externalLinkAttributes : { rel : "noopener noreferrer" } ,
2830 } ) ;
@@ -44,6 +46,7 @@ test("adds icon to external links", async () => {
4446
4547test ( "doesn't add icon to internal links" , async ( ) => {
4648 const html = await markdownToHtml ( "[link](/here)" , {
49+ allowInternalLinks : true ,
4750 linkAttributes : { class : "someclass" } ,
4851 externalLinkAttributes : { rel : "noopener noreferrer" } ,
4952 externalLinkIconHtml : "<svg></svg>" ,
@@ -75,3 +78,33 @@ test("aborts on img tags", async () => {
7578
7679 expect ( html ) . toBe ( null ) ;
7780} ) ;
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