File tree Expand file tree Collapse file tree
apps/server/src/workspace Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import * as FileSystem from "effect/FileSystem";
55import * as Layer from "effect/Layer" ;
66import * as Path from "effect/Path" ;
77
8+ import * as HostProcess from "@t3tools/shared/HostProcess" ;
9+
810import * as WorkspacePaths from "./WorkspacePaths.ts" ;
911
1012const layerTest = Layer . empty . pipe (
@@ -58,5 +60,25 @@ it.layer(layerTest)("WorkspacePathsLive", (it) => {
5860 ) ;
5961 } ) ,
6062 ) ;
63+
64+ // On Windows `\` is a separator, so these names cannot exist there.
65+ it . effect . skipIf ( HostProcess . Platform . defaultValue ( ) === "win32" ) (
66+ "keeps a backslash in a name as part of the name" ,
67+ ( ) =>
68+ Effect . gen ( function * ( ) {
69+ const workspacePaths = yield * WorkspacePaths . WorkspacePaths ;
70+ const path = yield * Path . Path ;
71+ const cwd = yield * makeTempDir ( ) ;
72+
73+ for ( const relativePath of [ "weird\\name.txt" , "..\\..\\etc" ] ) {
74+ expect (
75+ yield * workspacePaths . resolveRelativePathWithinRoot ( {
76+ workspaceRoot : cwd ,
77+ relativePath,
78+ } ) ,
79+ ) . toEqual ( { absolutePath : path . join ( cwd , relativePath ) , relativePath } ) ;
80+ }
81+ } ) ,
82+ ) ;
6183 } ) ;
6284} ) ;
Original file line number Diff line number Diff line change @@ -103,10 +103,6 @@ export class WorkspacePaths extends Context.Service<
103103 }
104104> ( ) ( "t3/workspace/WorkspacePaths" ) { }
105105
106- function toPosixRelativePath ( input : string ) : string {
107- return input . replaceAll ( "\\" , "/" ) ;
108- }
109-
110106const make = Effect . gen ( function * ( ) {
111107 const fileSystem = yield * FileSystem . FileSystem ;
112108 const path = yield * Path . Path ;
@@ -188,7 +184,10 @@ const make = Effect.gen(function* () {
188184 }
189185
190186 const absolutePath = path . resolve ( input . workspaceRoot , normalizedInputPath ) ;
191- const relativeToRoot = toPosixRelativePath ( path . relative ( input . workspaceRoot , absolutePath ) ) ;
187+ // Only the host separator becomes `/`: on POSIX `\` is a file name character.
188+ const relativeToRoot = path
189+ . relative ( input . workspaceRoot , absolutePath )
190+ . replaceAll ( path . sep , "/" ) ;
192191 if (
193192 relativeToRoot . length === 0 ||
194193 relativeToRoot === "." ||
You can’t perform that action at this time.
0 commit comments