@@ -217,11 +217,13 @@ await tmp.withDir(async (dir) => {
217217 t . is ( parsed . BRAND_NEW_KEY , "brand_new_value" )
218218 } )
219219
220- ava . serial ( "should handle Windows-style paths" , async ( t : Context ) => {
220+ ava . serial ( "should handle Windows-style paths (normalized to forward slashes) " , async ( t : Context ) => {
221221 const windowsPath = "C:\\Users\\JohnDoe\\Documents\\Project"
222+ const expectedNormalized = "C:/Users/JohnDoe/Documents/Project"
222223 await global . setEnvVar ( "WIN_PATH" , windowsPath )
223224 const { parsed } = dotenv . config ( { files : [ t . context . envFile ] } )
224- t . is ( parsed . WIN_PATH , windowsPath )
225+ // Paths are normalized to forward slashes to prevent .env parsing issues
226+ t . is ( parsed . WIN_PATH , expectedNormalized )
225227 } )
226228
227229 ava . serial ( "should handle POSIX-style paths" , async ( t : Context ) => {
@@ -233,37 +235,72 @@ await tmp.withDir(async (dir) => {
233235
234236 ava . serial ( "should handle paths with spaces" , async ( t : Context ) => {
235237 const windowsPath = "C:\\Program Files\\My App\\Config"
238+ const expectedWinNormalized = "C:/Program Files/My App/Config"
236239 const posixPath = "/home/user/My Documents/project"
237240
238241 await global . setEnvVar ( "WIN_SPACE_PATH" , windowsPath )
239242 await global . setEnvVar ( "POSIX_SPACE_PATH" , posixPath )
240243
241244 const { parsed } = dotenv . config ( { files : [ t . context . envFile ] } )
242- t . is ( parsed . WIN_SPACE_PATH , windowsPath )
245+ // Windows paths normalized to forward slashes, POSIX paths unchanged
246+ t . is ( parsed . WIN_SPACE_PATH , expectedWinNormalized )
243247 t . is ( parsed . POSIX_SPACE_PATH , posixPath )
244248 } )
245249
246250 ava . serial ( "should handle network paths and UNC paths" , async ( t : Context ) => {
247251 const uncPath = "\\\\server\\share\\folder"
252+ const expectedUncNormalized = "//server/share/folder"
248253 const networkPath = "//server/share/folder"
249254
250255 await global . setEnvVar ( "UNC_PATH" , uncPath )
251256 await global . setEnvVar ( "NETWORK_PATH" , networkPath )
252257
253258 const { parsed } = dotenv . config ( { files : [ t . context . envFile ] } )
254- t . is ( parsed . UNC_PATH , uncPath )
259+ // UNC paths normalized to forward slashes, network paths unchanged
260+ t . is ( parsed . UNC_PATH , expectedUncNormalized )
255261 t . is ( parsed . NETWORK_PATH , networkPath )
256262 } )
257263
258264 ava . serial ( "should handle relative paths" , async ( t : Context ) => {
259265 const winRelative = "..\\parent\\child"
266+ const expectedWinNormalized = "../parent/child"
260267 const posixRelative = "../parent/child"
261268
262269 await global . setEnvVar ( "WIN_RELATIVE" , winRelative )
263270 await global . setEnvVar ( "POSIX_RELATIVE" , posixRelative )
264271
265272 const { parsed } = dotenv . config ( { files : [ t . context . envFile ] } )
266- t . is ( parsed . WIN_RELATIVE , winRelative )
273+ // Windows relative paths normalized to forward slashes, POSIX paths unchanged
274+ t . is ( parsed . WIN_RELATIVE , expectedWinNormalized )
267275 t . is ( parsed . POSIX_RELATIVE , posixRelative )
268276 } )
277+
278+ ava . serial ( "should fix KENV and KIT_NODE_PATH issue (GitHub issue)" , async ( t : Context ) => {
279+ // This tests the exact scenario reported in the issue:
280+ // Windows paths with backslashes were being wrapped in quotes,
281+ // causing .env parsing to fail
282+ const kenvPath = "C:\\Users\\myusername\\.kenv"
283+ const kitNodePath = "C:\\Users\\myusername\\.kit\\nodejs\\22.9.0\\node.exe"
284+
285+ const expectedKenv = "C:/Users/myusername/.kenv"
286+ const expectedKitNode = "C:/Users/myusername/.kit/nodejs/22.9.0/node.exe"
287+
288+ // Use different var names to avoid confusing the path resolution
289+ await global . setEnvVar ( "TEST_KENV_PATH" , kenvPath )
290+ await global . setEnvVar ( "TEST_KIT_NODE_PATH" , kitNodePath )
291+
292+ // Read raw file to verify no backslashes in quotes
293+ const contents = await readFile ( t . context . envFile , "utf-8" )
294+ t . log ( "File contents:" , contents )
295+
296+ // Verify the file doesn't contain quoted backslash paths
297+ t . false ( contents . includes ( '="C:\\' ) , "Should not have quoted backslash paths" )
298+ // Verify it has normalized forward slash paths
299+ t . true ( contents . includes ( 'C:/Users/myusername' ) , "Should have normalized forward slash paths" )
300+
301+ // Verify dotenv can parse correctly
302+ const { parsed } = dotenv . config ( { files : [ t . context . envFile ] } )
303+ t . is ( parsed . TEST_KENV_PATH , expectedKenv , "Path should be normalized to forward slashes" )
304+ t . is ( parsed . TEST_KIT_NODE_PATH , expectedKitNode , "Path should be normalized to forward slashes" )
305+ } )
269306} )
0 commit comments