Skip to content

Commit bf1ea6a

Browse files
authored
Merge pull request #19 from cheeslide/patch-1
fix: start with .
2 parents aec372c + f0be996 commit bf1ea6a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ where
5858
let mut ita = path.components();
5959
let mut itb = base.components();
6060
let mut comps: Vec<Component> = vec![];
61+
62+
// ./foo and foo are the same
63+
if let Some(Component::CurDir) = ita.clone().next() {
64+
ita.next();
65+
}
66+
if let Some(Component::CurDir) = itb.clone().next() {
67+
itb.next();
68+
}
69+
6170
loop {
6271
match (ita.next(), itb.next()) {
6372
(None, None) => break,
@@ -136,6 +145,15 @@ mod utf8_paths {
136145
let mut ita = path.components();
137146
let mut itb = base.components();
138147
let mut comps: Vec<Utf8Component> = vec![];
148+
149+
// ./foo and foo are the same
150+
if let Some(Utf8Component::CurDir) = ita.clone().next() {
151+
ita.next();
152+
}
153+
if let Some(Utf8Component::CurDir) = itb.clone().next() {
154+
itb.next();
155+
}
156+
139157
loop {
140158
match (ita.next(), itb.next()) {
141159
(None, None) => break,
@@ -198,6 +216,9 @@ mod tests {
198216
assert_diff_paths("./foo", "./foo", Some(""));
199217
assert_diff_paths("/foo", "/foo", Some(""));
200218
assert_diff_paths("foo", "foo", Some(""));
219+
assert_diff_paths("./foo", "foo", Some(""));
220+
assert_diff_paths("foo", "./foo", Some(""));
221+
assert_diff_paths("foo/foo", "./foo/foo", Some(""));
201222

202223
assert_diff_paths("../foo/bar/baz", "../foo/bar/baz", Some("".into()));
203224
assert_diff_paths("foo/bar/baz", "foo/bar/baz", Some(""));
@@ -221,6 +242,8 @@ mod tests {
221242
assert_diff_paths("../foo", "../bar", Some("../foo"));
222243
assert_diff_paths("../foo", "../foo/bar/baz", Some("../.."));
223244
assert_diff_paths("../foo/bar/baz", "../foo", Some("bar/baz"));
245+
assert_diff_paths("../foo", "bar", Some("../../foo"));
246+
assert_diff_paths("foo", "../bar", None);
224247

225248
assert_diff_paths("foo/bar/baz", "foo", Some("bar/baz"));
226249
assert_diff_paths("foo/bar/baz", "foo/bar", Some("baz"));
@@ -242,6 +265,10 @@ mod tests {
242265
assert_diff_paths(".", "foo", Some("../."));
243266
assert_diff_paths("foo", ".", Some("foo"));
244267
assert_diff_paths("/foo", "/.", Some("foo"));
268+
269+
assert_diff_paths("./foo/bar/baz", "foo", Some("bar/baz"));
270+
assert_diff_paths("foo/bar/baz", "./foo", Some("bar/baz"));
271+
assert_diff_paths("./foo/bar/baz", "./foo", Some("bar/baz"));
245272
}
246273

247274
fn assert_diff_paths(path: &str, base: &str, expected: Option<&str>) {

0 commit comments

Comments
 (0)