Skip to content

Commit

Permalink
Fix exception after removing last relative component (#4011)
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp authored Sep 8, 2023
1 parent 1e38c83 commit cb0d6f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ String canonicalize(String pathString) {

// Pop directories off `newPath` if the component links upwards in the
// directory hierarchy.
while (relativeComponents.first == '..') {
while (relativeComponents.firstOrNull == '..') {
newPath = path.dirname(newPath);
relativeComponents.removeFirst();
}
Expand Down
19 changes: 19 additions & 0 deletions test/io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ void main() {
);
});

test('resolves a symlink to parent', () {
expect(
_withCanonicalTempDir((temp) {
_createDir(path.join(temp, 'linked-dir'));
_createDir(path.join(temp, 'linked-dir', 'a'));
_createDir(path.join(temp, 'linked-dir', 'b'));
createSymlink(
path.join(temp, 'linked-dir'),
path.join(temp, 'linked-dir', 'a', 'symlink'),
);
expect(
canonicalize(path.join(temp, 'linked-dir', 'a', 'symlink', 'b')),
equals(path.join(temp, 'linked-dir', 'b')),
);
}),
completes,
);
});

test('resolves a relative symlink', () {
expect(
_withCanonicalTempDir((temp) {
Expand Down

0 comments on commit cb0d6f9

Please sign in to comment.