@@ -14,6 +14,7 @@ import escapeStringRegexp from "escape-string-regexp";
1414import FileBrowser from "pages/fileBrowser" ;
1515import helpers from "utils/helpers" ;
1616import Path from "utils/Path" ;
17+ import Uri from "utils/Uri" ;
1718import Url from "utils/Url" ;
1819import constants from "./constants" ;
1920import * as FileList from "./fileList" ;
@@ -49,7 +50,28 @@ const isTerminalAccessiblePath = (url = "") => {
4950const convertToProotPath = ( url = "" ) => {
5051 const { alpineRoot, publicDir } = getTerminalPaths ( ) ;
5152 if ( isAcodeTerminalPublicSafUri ( url ) ) {
52- return "/public" ;
53+ try {
54+ const { docId } = Uri . parse ( url ) ;
55+ const cleanDocId = decodeURIComponent ( docId || "" ) ;
56+ if ( ! cleanDocId ) return "/public" ;
57+ if ( cleanDocId . startsWith ( publicDir ) ) {
58+ return cleanDocId . replace ( publicDir , "/public" ) || "/public" ;
59+ }
60+ if ( cleanDocId . startsWith ( "/public" ) ) {
61+ return cleanDocId ;
62+ }
63+ if ( cleanDocId . startsWith ( "public:" ) ) {
64+ const relativePath = cleanDocId . slice ( "public:" . length ) ;
65+ return relativePath ? Path . join ( "/public" , relativePath ) : "/public" ;
66+ }
67+ const relativePath = cleanDocId . replace ( / ^ \/ + / , "" ) ;
68+ return relativePath ? Path . join ( "/public" , relativePath ) : "/public" ;
69+ } catch ( error ) {
70+ console . warn (
71+ `Failed to parse public SAF URI for terminal conversion: ${ url } ` ,
72+ ) ;
73+ return "/public" ;
74+ }
5375 }
5476 const cleanUrl = url . replace ( / ^ f i l e : \/ \/ / , "" ) ;
5577 if ( cleanUrl . startsWith ( publicDir ) ) {
0 commit comments