Unverified Commit 5be8d2ee authored by zoomdong's avatar zoomdong Committed by GitHub

TURBOPACK: support parse windows absolute path with single slash (#92076)

The path like which starts with single slash:

```bash
C:/Users/demo/src/index.ts
```

Shoud parse as windows path.
parent a21f3f40
...@@ -90,7 +90,8 @@ fn split_off_query_fragment(mut raw: &str) -> (Pattern, RcStr, RcStr) { ...@@ -90,7 +90,8 @@ fn split_off_query_fragment(mut raw: &str) -> (Pattern, RcStr, RcStr) {
(Pattern::Constant(RcStr::from(raw)), query, hash) (Pattern::Constant(RcStr::from(raw)), query, hash)
} }
static WINDOWS_PATH: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[A-Za-z]:\\|\\\\").unwrap()); static WINDOWS_PATH: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[A-Za-z]:[/\\]|^\\\\").unwrap());
static URI_PATH: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^([^/\\:]+:)(.+)$").unwrap()); static URI_PATH: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^([^/\\:]+:)(.+)$").unwrap());
static DATA_URI_REMAINDER: LazyLock<Regex> = static DATA_URI_REMAINDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^([^;,]*)(?:;([^,]+))?,(.*)$").unwrap()); LazyLock::new(|| Regex::new(r"^([^;,]*)(?:;([^,]+))?,(.*)$").unwrap());
...@@ -855,6 +856,27 @@ pub async fn stringify_data_uri( ...@@ -855,6 +856,27 @@ pub async fn stringify_data_uri(
mod tests { mod tests {
use super::*; use super::*;
#[test]
fn test_parse_windows_paths() {
assert_eq!(
Request::Windows {
path: rcstr!(r"C:\Users\demo\src\index.ts").into(),
query: rcstr!(""),
fragment: rcstr!(""),
},
Request::parse_ref(rcstr!(r"C:\Users\demo\src\index.ts").into())
);
assert_eq!(
Request::Windows {
path: rcstr!("C:/Users/demo/src/index.ts").into(),
query: rcstr!(""),
fragment: rcstr!(""),
},
Request::parse_ref(rcstr!("C:/Users/demo/src/index.ts").into())
);
}
#[test] #[test]
fn test_parse_module() { fn test_parse_module() {
assert_eq!( assert_eq!(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment