File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ function isAnchorLinkAllowed(value: string) {
15
15
. replace ( / & # ( \d + ) ; ? / g, '' )
16
16
. replace ( / & [ a - z ] + ; ? / gi, '' )
17
17
18
+ // Check if the URL is a relative path
19
+ if ( urlSanitized . startsWith ( '/' ) || urlSanitized . startsWith ( './' ) || urlSanitized . startsWith ( '../' ) ) {
20
+ return true
21
+ }
22
+
18
23
try {
19
24
const url = new URL ( urlSanitized )
20
25
if ( unsafeLinkPrefix . some ( prefix => url . protocol . toLowerCase ( ) . startsWith ( prefix ) ) ) {
Original file line number Diff line number Diff line change
1
+ import { expect , it } from 'vitest'
2
+ import { parseMarkdown } from '../utils/parser'
3
+
4
+ const md = `
5
+ # Some headline
6
+
7
+ Following are some image links:
8
+
9
+ 
10
+
11
+ 
12
+
13
+ 
14
+
15
+ ` . trim ( )
16
+
17
+ it ( 'Sanity test for image links, all should be allowed' , async ( ) => {
18
+ const { body } = await parseMarkdown ( md )
19
+
20
+ expect ( body . children [ 2 ] . children [ 0 ] . tag ) . toEqual ( 'img' )
21
+ expect ( body . children [ 2 ] . children [ 0 ] . props . src ) . toEqual ( '/path/to/my/image.png' )
22
+
23
+ expect ( body . children [ 3 ] . children [ 0 ] . tag ) . toEqual ( 'img' )
24
+ expect ( body . children [ 3 ] . children [ 0 ] . props . src ) . toEqual ( '../relative/path/to/image.png' )
25
+
26
+ expect ( body . children [ 4 ] . children [ 0 ] . tag ) . toEqual ( 'img' )
27
+ expect ( body . children [ 4 ] . children [ 0 ] . props . src ) . toEqual ( 'https://placehold.co/200x200.png' )
28
+ } )
You can’t perform that action at this time.
0 commit comments