@@ -40,6 +40,9 @@ pub fn resolve_file_uri(uri: &str, base_path: &Path) -> Result<String, FileUriEr
4040 return Err ( FileUriError :: InvalidUri { uri : uri. to_string ( ) } ) ;
4141 }
4242
43+ // Expand tilde to home directory
44+ let path_str = shellexpand:: tilde ( path_str) . to_string ( ) ;
45+
4346 // Resolve the path
4447 let resolved_path = if path_str. starts_with ( '/' ) {
4548 // Absolute path
@@ -142,4 +145,28 @@ mod tests {
142145
143146 Ok ( ( ) )
144147 }
148+
149+ #[ test]
150+ fn test_tilde_expansion ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
151+ // Test that tilde gets expanded by verifying the path is absolute after expansion
152+ // We can't easily mock HOME and don't want to write test files there, but we can verify
153+ // the expansion behavior using error messages
154+ let uri = "file://~/test.txt" ;
155+ let base = Path :: new ( "/some/other/path" ) ;
156+
157+ // This will fail to find the file (expected), but the error should show
158+ // an expanded absolute path, not a path with literal ~
159+ let result = resolve_file_uri ( uri, base) ;
160+
161+ match result {
162+ Err ( FileUriError :: FileNotFound { path } ) => {
163+ // Verify the path was expanded (should start with / not ~)
164+ assert ! ( path. starts_with( "/" ) , "Path should be absolute after tilde expansion, got: {:?}" , path) ;
165+ assert ! ( !path. to_string_lossy( ) . contains( "~" ) , "Path should not contain literal tilde, got: {:?}" , path) ;
166+ } ,
167+ _ => panic ! ( "Expected FileNotFound error" ) ,
168+ }
169+
170+ Ok ( ( ) )
171+ }
145172}
0 commit comments