Skip to content

fix: normalize preprocessed path #1157

Closed
gogoolu wants to merge 1 commit into
EmmyLuaLs:mainfrom
gogoolu:normalize-config-path
Closed

fix: normalize preprocessed path #1157
gogoolu wants to merge 1 commit into
EmmyLuaLs:mainfrom
gogoolu:normalize-config-path

Conversation

@gogoolu

@gogoolu gogoolu commented Jul 9, 2026

Copy link
Copy Markdown

fix this bug: #1156

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: pre_process.rs Changes

Issues Identified:

  1. Potential Performance Concern 🔴

    • path.canonicalize() performs filesystem I/O which could be slow for many paths
    • Consider caching or using a lighter normalization approach if performance is critical
  2. Error Handling Gap ⚠️

    • canonicalize() silently falls back to original path on failure, which might hide real filesystem issues
    • Consider logging or returning a Result type for better error propagation
  3. Redundant URI Conversion 🤔

    • Converting to URI and back seems unnecessary for simple path normalization
    • file_path_to_uri and uri_to_file_path might introduce platform-specific issues (e.g., Windows drive letters)

Recommendations:

  1. Simplify normalization if URI conversion isn't strictly required:
fn normalize_path_string(path: String) -> String {
    PathBuf::from(path)
        .canonicalize()
        .unwrap_or_else(|_| PathBuf::from(&path))
        .to_string_lossy()
        .to_string()
}
  1. Add logging for failed canonicalization:
fn normalize_path_string(path: String) -> String {
    let path_buf = PathBuf::from(&path);
    match path_buf.canonicalize() {
        Ok(canonical) => canonical.to_string_lossy().to_string(),
        Err(e) => {
            log::warn!("Failed to canonicalize path '{}': {}", path, e);
            path
        }
    }
}
  1. Consider platform compatibility - Test on Windows where path separators and drive letters may behave differently with URI conversion.

Overall Assessment:

The change adds path normalization which is generally good practice, but the implementation could be simplified and made more robust. The URI round-trip appears unnecessary unless there's a specific requirement for URI-encoded paths.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a path normalization step using a new helper function normalize_path_string in pre_process.rs. Feedback highlights a critical issue on Windows where std::fs::canonicalize returns verbatim paths starting with \\?\ that are unsupported by the url crate, leading to conversion failures. A code suggestion was provided to strip this prefix on Windows to prevent files from being silently ignored.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +184 to +192
fn normalize_path_string(path: String) -> String {
let path = PathBuf::from(path);
let path = path.canonicalize().unwrap_or(path);
file_path_to_uri(&path)
.and_then(|uri| uri_to_file_path(&uri))
.unwrap_or(path)
.to_string_lossy()
.to_string()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

On Windows, std::fs::canonicalize returns a verbatim path starting with the \\?\ prefix (e.g., \\?\C:\path or \\?\UNC\server\share). The url crate's Url::from_file_path does not support verbatim paths and will return Err(()). This causes file_path_to_uri to return None, meaning normalize_path_string will fall back to returning the verbatim path. Consequently, any subsequent operations attempting to convert this path to a URI (such as when loading or updating files) will fail, causing files to be silently ignored on Windows. To fix this, we should strip the verbatim prefix on Windows before converting the path to a URI.

Suggested change
fn normalize_path_string(path: String) -> String {
let path = PathBuf::from(path);
let path = path.canonicalize().unwrap_or(path);
file_path_to_uri(&path)
.and_then(|uri| uri_to_file_path(&uri))
.unwrap_or(path)
.to_string_lossy()
.to_string()
}
fn normalize_path_string(path: String) -> String {
let path = PathBuf::from(path);
let path = path.canonicalize().unwrap_or(path);
#[cfg(windows)]
let path = {
let path_str = path.to_string_lossy();
if let Some(stripped) = path_str.strip_prefix("\\\\?\\UNC\\") {
PathBuf::from(format!("\\\\{}", stripped))
} else if let Some(stripped) = path_str.strip_prefix("\\\\?\\") {
PathBuf::from(stripped)
} else {
path
}
};
file_path_to_uri(&path)
.and_then(|uri| uri_to_file_path(&uri))
.unwrap_or(path)
.to_string_lossy()
.to_string()
}

@CppCXY CppCXY closed this Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants