Fix absolute working directory bugs on POSIX (#36)
Closes #35
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b5fbeb9..e23e380 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.5.1
+
+* Fix a number of bugs that occurred when the current working directory was `/`
+ on Linux or Mac OS.
+
## 1.5.0
* Add a `setExtension()` top-level function and `Context` method.
diff --git a/lib/path.dart b/lib/path.dart
index 8e87c33..9885859 100644
--- a/lib/path.dart
+++ b/lib/path.dart
@@ -91,10 +91,11 @@
return _current;
} else {
var path = uri.toFilePath();
- // Remove trailing '/' or '\'.
+ // Remove trailing '/' or '\' unless it is the only thing left
+ // (for instance the root on Linux).
var lastIndex = path.length - 1;
assert(path[lastIndex] == '/' || path[lastIndex] == '\\');
- _current = path.substring(0, lastIndex);
+ _current = lastIndex == 0 ? path : path.substring(0, lastIndex);
return _current;
}
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 5e94e09..30a8dff 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: path
-version: 1.5.0
+version: 1.5.1
author: Dart Team <misc@dartlang.org>
description: >
A string-based path manipulation library. All of the path operations you know
diff --git a/test/io_test.dart b/test/io_test.dart
index f15f82d..82d8b09 100644
--- a/test/io_test.dart
+++ b/test/io_test.dart
@@ -55,4 +55,25 @@
io.Directory.current = dir;
}
});
+
+ // Regression test for #35. This tests against the *actual* working directory
+ // rather than just a custom context because we do some processing in
+ // [path.current] that has clobbered the root in the past.
+ test('absolute works on root working directory', () {
+ var dir = path.current;
+ try {
+ io.Directory.current = path.rootPrefix(path.current);
+
+ expect(path.relative(path.absolute('foo/bar'), from: path.current),
+ path.relative(path.absolute('foo/bar')));
+
+ expect(path.normalize(path.absolute('foo/bar')),
+ equals(path.normalize(path.join(path.current, '../foo/bar'))));
+
+ expect(path.normalize(path.absolute('foo/bar')),
+ equals(path.normalize(path.join(path.current, '../foo/bar'))));
+ } finally {
+ io.Directory.current = dir;
+ }
+ });
}