@@ -5,6 +5,39 @@ async function loadSubject() {
55 return import ( "./file-links.ts" ) ;
66}
77
8+ test ( "opens local files for plain, Command, and Ctrl left clicks" , async ( ) => {
9+ const { shouldOpenLocalFileInApp } = await loadSubject ( ) ;
10+ const click = {
11+ defaultPrevented : false ,
12+ button : 0 ,
13+ metaKey : false ,
14+ ctrlKey : false ,
15+ shiftKey : false ,
16+ altKey : false ,
17+ } ;
18+
19+ assert . equal ( shouldOpenLocalFileInApp ( click ) , true ) ;
20+ assert . equal ( shouldOpenLocalFileInApp ( { ...click , metaKey : true } ) , true ) ;
21+ assert . equal ( shouldOpenLocalFileInApp ( { ...click , ctrlKey : true } ) , true ) ;
22+ } ) ;
23+
24+ test ( "leaves secondary modified and non-left clicks to the browser" , async ( ) => {
25+ const { shouldOpenLocalFileInApp } = await loadSubject ( ) ;
26+ const click = {
27+ defaultPrevented : false ,
28+ button : 0 ,
29+ metaKey : false ,
30+ ctrlKey : false ,
31+ shiftKey : false ,
32+ altKey : false ,
33+ } ;
34+
35+ assert . equal ( shouldOpenLocalFileInApp ( { ...click , shiftKey : true } ) , false ) ;
36+ assert . equal ( shouldOpenLocalFileInApp ( { ...click , altKey : true } ) , false ) ;
37+ assert . equal ( shouldOpenLocalFileInApp ( { ...click , button : 1 } ) , false ) ;
38+ assert . equal ( shouldOpenLocalFileInApp ( { ...click , defaultPrevented : true } ) , false ) ;
39+ } ) ;
40+
841test ( "resolves absolute markdown file links and strips line suffixes" , async ( ) => {
942 const { resolveLocalFileHref } = await loadSubject ( ) ;
1043
@@ -69,6 +102,21 @@ test("does not treat app or external URLs as file links", async () => {
69102 assert . equal ( resolveLocalFileHref ( "//example.com/a.ts" , "/home/me/project" ) , null ) ;
70103} ) ;
71104
105+ test ( "decodes file URL paths once after parsing URL delimiters" , async ( ) => {
106+ const { resolveLocalFileHref } = await loadSubject ( ) ;
107+
108+ for ( const [ href , expected ] of [
109+ [ "file:///home/me/project/C%23/report.html" , "/home/me/project/C#/report.html" ] ,
110+ [ "file:///home/me/project/report%3F.html" , "/home/me/project/report?.html" ] ,
111+ [ "file:///home/me/project/report%2520.html" , "/home/me/project/report%20.html" ] ,
112+ [ "file:///home/me/project/report%20one.html?raw=1#L10" , "/home/me/project/report one.html" ] ,
113+ [ "file:///C:/Users/me/C%23/report%2520.html" , "C:/Users/me/C#/report%20.html" ] ,
114+ [ "file://server/share/C%23/report%2520.html" , "//server/share/C#/report%20.html" ] ,
115+ ] ) {
116+ assert . equal ( resolveLocalFileHref ( href , "/home/me/project" ) , expected , href ) ;
117+ }
118+ } ) ;
119+
72120test ( "resolves Windows file URLs without a synthetic leading slash" , async ( ) => {
73121 const { resolveLocalFileHref } = await loadSubject ( ) ;
74122
0 commit comments