From 90006fc351988aef3f3d90ba6cfdb17ad1f3e10a Mon Sep 17 00:00:00 2001 From: Progyan Sen Date: Sat, 15 Nov 2025 20:01:42 +0530 Subject: [PATCH 1/3] fix: resolve TURBO_CONFIG_DIR_PATH to absolute path --- crates/turborepo-dirs/src/lib.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/turborepo-dirs/src/lib.rs b/crates/turborepo-dirs/src/lib.rs index c8c28b9cfa02b..12865cf298681 100644 --- a/crates/turborepo-dirs/src/lib.rs +++ b/crates/turborepo-dirs/src/lib.rs @@ -13,7 +13,20 @@ use turbopath::{AbsoluteSystemPathBuf, PathError}; /// is set, it will return that path instead of `dirs_next::config_dir`. pub fn config_dir() -> Result, PathError> { if let Ok(dir) = std::env::var("TURBO_CONFIG_DIR_PATH") { - return AbsoluteSystemPathBuf::new(dir).map(Some); + let raw = std::path::PathBuf::from(&dir); + + // Resolve to absolute path if necessary + let abs = if raw.is_absolute() { + raw + } else { + std::env::current_dir()?.join(raw) + }; + + let abs_str = abs + .to_str() + .ok_or_else(|| PathError::InvalidUnicode(dir.clone()))?; + + return AbsoluteSystemPathBuf::new(abs_str).map(Some); } dirs_config_dir() From 3d78934bc1404d1c19eddd95d898b315fe806873 Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Mon, 17 Nov 2025 21:44:14 -0700 Subject: [PATCH 2/3] Handle empty env var being set. --- crates/turborepo-dirs/src/lib.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/turborepo-dirs/src/lib.rs b/crates/turborepo-dirs/src/lib.rs index 85b35a58b8e87..675ce7e15a1ef 100644 --- a/crates/turborepo-dirs/src/lib.rs +++ b/crates/turborepo-dirs/src/lib.rs @@ -13,6 +13,11 @@ use turbopath::{AbsoluteSystemPathBuf, PathError}; /// is set, it will return that path instead of `dirs_next::config_dir`. pub fn config_dir() -> Result, PathError> { if let Ok(dir) = std::env::var("TURBO_CONFIG_DIR_PATH") { + // Reject empty strings per Unix convention + if dir.is_empty() { + return Err(PathError::InvalidUnicode(dir)); + } + let raw = std::path::PathBuf::from(&dir); // Resolve to absolute path if necessary @@ -22,9 +27,7 @@ pub fn config_dir() -> Result, PathError> { std::env::current_dir()?.join(raw) }; - let abs_str = abs - .to_str() - .ok_or_else(|| PathError::InvalidUnicode(dir.clone()))?; + let abs_str = abs.to_str().ok_or_else(|| PathError::InvalidUnicode(dir))?; return AbsoluteSystemPathBuf::new(abs_str).map(Some); } @@ -41,6 +44,11 @@ pub fn config_dir() -> Result, PathError> { /// is set, it will return that path instead of `dirs_next::config_dir`. pub fn vercel_config_dir() -> Result, PathError> { if let Ok(dir) = std::env::var("VERCEL_CONFIG_DIR_PATH") { + // Reject empty strings per Unix convention. + if dir.is_empty() { + return Err(PathError::InvalidUnicode(dir)); + } + return AbsoluteSystemPathBuf::new(dir).map(Some); } @@ -86,14 +94,18 @@ mod tests { } #[test] - fn test_config_dir_with_invalid_env_var() { - // Set TURBO_CONFIG_DIR_PATH to a relative path (invalid) + fn test_config_dir_with_relative_path() { + // Set TURBO_CONFIG_DIR_PATH to a relative path (should be resolved to absolute) unsafe { env::set_var("TURBO_CONFIG_DIR_PATH", "relative/path"); } let result = config_dir(); - assert!(result.is_err()); + assert!(result.is_ok()); + let path = result.unwrap(); + assert!(path.is_some()); + // Verify it was resolved to an absolute path + assert!(path.unwrap().as_path().is_absolute()); unsafe { env::remove_var("TURBO_CONFIG_DIR_PATH"); From ee9c21ead87d706011fcdba2f0a616694337d7bf Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Mon, 17 Nov 2025 22:23:06 -0700 Subject: [PATCH 3/3] clippy --- crates/turborepo-dirs/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/turborepo-dirs/src/lib.rs b/crates/turborepo-dirs/src/lib.rs index 675ce7e15a1ef..3181bd15c4087 100644 --- a/crates/turborepo-dirs/src/lib.rs +++ b/crates/turborepo-dirs/src/lib.rs @@ -27,7 +27,7 @@ pub fn config_dir() -> Result, PathError> { std::env::current_dir()?.join(raw) }; - let abs_str = abs.to_str().ok_or_else(|| PathError::InvalidUnicode(dir))?; + let abs_str = abs.to_str().ok_or(PathError::InvalidUnicode(dir))?; return AbsoluteSystemPathBuf::new(abs_str).map(Some); }