Skip to content

Commit

Permalink
Merge pull request #46 from devbrains-com/feature/fix_convertpath_to_…
Browse files Browse the repository at this point in the history
…posix

Fix convert_path_to_posix for mixed paths
  • Loading branch information
jantimon authored and devbrains-com committed Dec 17, 2024
1 parent 4c1b181 commit a6de68b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion swc/swc-plugin-css-variable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn relative_posix_path(base_path: &str, filename: &str) -> String {
/// - "/foo/bar" -> "/foo/bar"
fn convert_path_to_posix(path: &str) -> String {
lazy_static! {
static ref PATH_REPLACEMENT_REGEX: Regex = Regex::new(r":\\|\\").unwrap();
static ref PATH_REPLACEMENT_REGEX: Regex = Regex::new(r":\\|\\|:/").unwrap();
}

PATH_REPLACEMENT_REGEX.replace_all(path, "/").to_string()
Expand All @@ -91,6 +91,14 @@ mod tests {
);
}

#[test]
fn test_relative_path_windows_forward_slash() {
assert_eq!(
relative_posix_path(r"E:\foo", "E:/foo/bar/file.tsx"),
"bar/file.tsx"
);
}

#[test]
fn test_convert_unix_path() {
assert_eq!(convert_path_to_posix(r"/foo/bar"), "/foo/bar");
Expand Down

0 comments on commit a6de68b

Please sign in to comment.