@@ -30,6 +30,12 @@ type BuildRequestPartsInput = {
3030const absolute = ( directory : string , path : string ) =>
3131 path . startsWith ( "/" ) ? path : ( directory + "/" + path ) . replace ( "//" , "/" )
3232
33+ const encodeFilePath = ( filepath : string ) : string =>
34+ filepath
35+ . split ( "/" )
36+ . map ( ( segment ) => encodeURIComponent ( segment ) )
37+ . join ( "/" )
38+
3339const fileQuery = ( selection : FileSelection | undefined ) =>
3440 selection ? `?start=${ selection . startLine } &end=${ selection . endLine } ` : ""
3541
@@ -99,7 +105,7 @@ export function buildRequestParts(input: BuildRequestPartsInput) {
99105 id : Identifier . ascending ( "part" ) ,
100106 type : "file" ,
101107 mime : "text/plain" ,
102- url : `file://${ path } ${ fileQuery ( attachment . selection ) } ` ,
108+ url : `file://${ encodeFilePath ( path ) } ${ fileQuery ( attachment . selection ) } ` ,
103109 filename : getFilename ( attachment . path ) ,
104110 source : {
105111 type : "file" ,
@@ -129,7 +135,7 @@ export function buildRequestParts(input: BuildRequestPartsInput) {
129135 const used = new Set ( files . map ( ( part ) => part . url ) )
130136 const context = input . context . flatMap ( ( item ) => {
131137 const path = absolute ( input . sessionDirectory , item . path )
132- const url = `file://${ path } ${ fileQuery ( item . selection ) } `
138+ const url = `file://${ encodeFilePath ( path ) } ${ fileQuery ( item . selection ) } `
133139 const comment = item . comment ?. trim ( )
134140 if ( ! comment && used . has ( url ) ) return [ ]
135141 used . add ( url )
0 commit comments