diff options
Diffstat (limited to 'crates/vfs/src')
-rw-r--r-- | crates/vfs/src/file_set.rs | 2 | ||||
-rw-r--r-- | crates/vfs/src/vfs_path.rs | 16 |
2 files changed, 10 insertions, 8 deletions
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs index 0173f7464..d0ddeafe7 100644 --- a/crates/vfs/src/file_set.rs +++ b/crates/vfs/src/file_set.rs | |||
@@ -18,7 +18,7 @@ impl FileSet { | |||
18 | pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { | 18 | pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
19 | let mut base = self.paths[&anchor].clone(); | 19 | let mut base = self.paths[&anchor].clone(); |
20 | base.pop(); | 20 | base.pop(); |
21 | let path = base.join(path); | 21 | let path = base.join(path)?; |
22 | let res = self.files.get(&path).copied(); | 22 | let res = self.files.get(&path).copied(); |
23 | res | 23 | res |
24 | } | 24 | } |
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 940f91d0e..dc3031ada 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs | |||
@@ -22,15 +22,15 @@ impl VfsPath { | |||
22 | VfsPathRepr::VirtualPath(_) => None, | 22 | VfsPathRepr::VirtualPath(_) => None, |
23 | } | 23 | } |
24 | } | 24 | } |
25 | pub fn join(&self, path: &str) -> VfsPath { | 25 | pub fn join(&self, path: &str) -> Option<VfsPath> { |
26 | match &self.0 { | 26 | match &self.0 { |
27 | VfsPathRepr::PathBuf(it) => { | 27 | VfsPathRepr::PathBuf(it) => { |
28 | let res = it.join(path).normalize(); | 28 | let res = it.join(path).normalize(); |
29 | VfsPath(VfsPathRepr::PathBuf(res)) | 29 | Some(VfsPath(VfsPathRepr::PathBuf(res))) |
30 | } | 30 | } |
31 | VfsPathRepr::VirtualPath(it) => { | 31 | VfsPathRepr::VirtualPath(it) => { |
32 | let res = it.join(path); | 32 | let res = it.join(path)?; |
33 | VfsPath(VfsPathRepr::VirtualPath(res)) | 33 | Some(VfsPath(VfsPathRepr::VirtualPath(res))) |
34 | } | 34 | } |
35 | } | 35 | } |
36 | } | 36 | } |
@@ -101,13 +101,15 @@ impl VirtualPath { | |||
101 | self.0 = self.0[..pos].to_string(); | 101 | self.0 = self.0[..pos].to_string(); |
102 | true | 102 | true |
103 | } | 103 | } |
104 | fn join(&self, mut path: &str) -> VirtualPath { | 104 | fn join(&self, mut path: &str) -> Option<VirtualPath> { |
105 | let mut res = self.clone(); | 105 | let mut res = self.clone(); |
106 | while path.starts_with("../") { | 106 | while path.starts_with("../") { |
107 | assert!(res.pop()); | 107 | if !res.pop() { |
108 | return None; | ||
109 | } | ||
108 | path = &path["../".len()..] | 110 | path = &path["../".len()..] |
109 | } | 111 | } |
110 | res.0 = format!("{}/{}", res.0, path); | 112 | res.0 = format!("{}/{}", res.0, path); |
111 | res | 113 | Some(res) |
112 | } | 114 | } |
113 | } | 115 | } |