Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sigurdm opened this issue Jan 3, 2022 · 1 comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sigurdm
Copy link

sigurdm commented Jan 3, 2022

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 lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label May 1, 2023
@lrhn
Copy link
Member

lrhn commented May 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants