diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-08-23 03:58:59 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-23 09:41:08 -0400 |
commit | ecb955929fd528f19c5fab9e4e904b621d8cf94d (patch) | |
tree | adbbce9bc26a3189cdb5b67ae8aa3d15299ad704 | |
parent | e2f9b0e6fd01c4ad8d7fc966a531e48e5aaa334f (diff) |
Normalize windows paths.
Add resolve_module test
-rw-r--r-- | src/deno_dir.rs | 45 | ||||
-rw-r--r-- | src/fs.rs | 10 | ||||
-rw-r--r-- | src/handlers.rs | 3 |
3 files changed, 31 insertions, 27 deletions
diff --git a/src/deno_dir.rs b/src/deno_dir.rs index b8573a018..03e5b3a69 100644 --- a/src/deno_dir.rs +++ b/src/deno_dir.rs @@ -250,29 +250,15 @@ impl DenoDir { match j.scheme() { "file" => { - let mut p = j - .to_file_path() - .unwrap() - .into_os_string() - .into_string() - .unwrap(); - - if cfg!(target_os = "windows") { - // On windows, replace backward slashes to forward slashes. - // TODO(piscisaureus): This may not me be right, I just did it to make - // the tests pass. - p = p.replace("\\", "/"); - } - - module_name = p.to_string(); - filename = p.to_string(); + let mut p = fs::normalize_path(j.to_file_path().unwrap().as_ref()); + module_name = p.clone(); + filename = p; } _ => { module_name = module_specifier.to_string(); - filename = get_cache_filename(self.deps.as_path(), j) - .to_str() - .unwrap() - .to_string(); + filename = fs::normalize_path( + get_cache_filename(self.deps.as_path(), j).as_ref(), + ) } } @@ -422,6 +408,13 @@ fn test_src_file_to_url() { fn test_resolve_module() { let (_temp_dir, deno_dir) = test_setup(); + let d = fs::normalize_path( + deno_dir + .deps + .join("localhost/testdata/subdir/print_hello.ts") + .as_ref(), + ); + let test_cases = [ ( "./subdir/print_hello.ts", @@ -453,14 +446,14 @@ fn test_resolve_module() { add_root!("/this/module/got/imported.js"), add_root!("/this/module/got/imported.js"), ), + ( + "http://localhost:4545/testdata/subdir/print_hello.ts", + add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts"), + "http://localhost:4545/testdata/subdir/print_hello.ts", + d.as_ref(), + ), /* ( - "http://localhost:4545/testdata/subdir/print_hello.ts", - add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts"), - "http://localhost:4545/testdata/subdir/print_hello.ts", - path.Join(SrcDir, "localhost:4545/testdata/subdir/print_hello.ts"), - ), - ( path.Join(SrcDir, "unpkg.com/liltest@0.0.5/index.ts"), ".", "http://unpkg.com/liltest@0.0.5/index.ts", @@ -34,3 +34,13 @@ pub fn mkdir(path: &Path) -> std::io::Result<()> { } }) } + +pub fn normalize_path(path: &Path) -> String { + let s = String::from(path.to_str().unwrap()); + if cfg!(windows) { + // TODO This isn't correct. Probbly should iterate over components. + s.replace("\\", "/") + } else { + s + } +} diff --git a/src/handlers.rs b/src/handlers.rs index 1b8a59173..f0bb6f51f 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -127,7 +127,8 @@ fn handle_start( let argv_off = builder.create_vector_of_strings(argv.as_slice()); let cwd_path = std::env::current_dir().unwrap(); - let cwd_off = builder.create_string(cwd_path.to_str().unwrap()); + let cwd_off = + builder.create_string(fs::normalize_path(cwd_path.as_ref()).as_ref()); let msg = msg::StartRes::create( builder, |