@@ -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,32 @@ 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 = / : : / . test ( url )
56+ ? decodeURIComponent ( docId || "" )
57+ : docId || "" ;
58+ if ( ! cleanDocId ) return "/public" ;
59+ if ( cleanDocId . startsWith ( publicDir ) ) {
60+ return cleanDocId . replace ( publicDir , "/public" ) || "/public" ;
61+ }
62+ if ( cleanDocId . startsWith ( "/public" ) ) {
63+ return cleanDocId ;
64+ }
65+ if ( cleanDocId . startsWith ( "public:" ) ) {
66+ const relativePath = cleanDocId . slice ( "public:" . length ) ;
67+ return relativePath ? Path . join ( "/public" , relativePath ) : "/public" ;
68+ }
69+ const relativePath = cleanDocId
70+ . replace ( / ^ \/ + / , "" )
71+ . replace ( / ^ p u b l i c \/ / , "" ) ;
72+ return relativePath ? Path . join ( "/public" , relativePath ) : "/public" ;
73+ } catch ( error ) {
74+ console . warn (
75+ `Failed to parse public SAF URI for terminal conversion: ${ url } ` ,
76+ ) ;
77+ return "/public" ;
78+ }
5379 }
5480 const cleanUrl = url . replace ( / ^ f i l e : \/ \/ / , "" ) ;
5581 if ( cleanUrl . startsWith ( publicDir ) ) {
0 commit comments