Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: normalize Windows paths in ModuleId constructors #1744

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions crates/mako/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ impl PartialOrd for ModuleId {
impl ModuleId {
// we use absolute path as module id now
pub fn new(id: String) -> Self {
Self { id }
Self {
id: win_path(id.as_str()),

Choose a reason for hiding this comment

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

Ensure that the win_path function correctly handles all edge cases for path normalization, especially for paths that may contain special characters or invalid sequences.

}
}

pub fn generate(&self, context: &Arc<Context>) -> String {
Expand All @@ -304,20 +306,22 @@ impl ModuleId {

impl From<String> for ModuleId {
fn from(id: String) -> Self {
Self { id }
Self {
id: win_path(id.as_str()),
}
}
}

impl From<&str> for ModuleId {
fn from(id: &str) -> Self {
Self { id: id.to_string() }
Self { id: win_path(id) }
}
}

impl From<PathBuf> for ModuleId {
fn from(path: PathBuf) -> Self {
Self {
id: path.to_string_lossy().to_string(),
id: win_path(path.to_string_lossy().to_string().as_str()),
}
}
}
Expand Down
Loading