dart-lang/path

`isWithin` has surprising behavior when `base` ends with `/.` and `child` starts with `.`

Opened this issue · 1 comments

import 'package:path/path.dart';

void main(List<String> args) {
  print(isWithin('/dir/.', '/dir/.file'));
  print(isWithin('/dir/.', '/dir/file'));
}

Prints

> dart a.dart
false
true
lrhn commented

That's a bug. A path being with another means the latter being a prefix of the former and ending at a path separator.

Seems we're too eagerly checking for the latter here, and not letting /dir/. be seen as /dir/./.

The code must assume that a path cannot be a prefix of a longer path, not end at a path separator of the longer path, and still be valid.

We do have some code which tries to address this case, but it must not be run in this case, for some reason:
https://github.com/dart-lang/path/blob/master/lib/src/context.dart#L721