Skip to content

Commit ec85232

Browse files
committed
Fix case-insensitive absolute listing.
This goes to show that we shouldn't avoid using path functions in the name of efficiency. We were using a raw substring to get a relative path, and it failed for absolute roots because they didn't have an extra "/" added to the end. Closes flutter#4 [email protected] Review URL: https://codereview.chromium.org//1773293002 .
1 parent 445a10b commit ec85232

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.1
2+
3+
* Fix a bug where listing an absolute glob with `caseInsensitive: false` failed.
4+
15
## 1.1.0
26

37
* Add a `caseSensitive` named parameter to `new Glob()` that controls whether

lib/src/list_tree.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class _ListTreeNode {
314314
Stream<FileSystemEntity> list(String dir, {bool followLinks: true}) {
315315
if (isRecursive) {
316316
return new Directory(dir).list(recursive: true, followLinks: followLinks)
317-
.where((entity) => _matches(entity.path.substring(dir.length + 1)));
317+
.where((entity) => _matches(p.relative(entity.path, from: dir)));
318318
}
319319

320320
var resultPool = new StreamPool();
@@ -333,7 +333,7 @@ class _ListTreeNode {
333333
var resultController = new StreamController(sync: true);
334334
resultPool.add(resultController.stream);
335335
new Directory(dir).list(followLinks: followLinks).listen((entity) {
336-
var basename = entity.path.substring(dir.length + 1);
336+
var basename = p.relative(entity.path, from: dir);
337337
if (_matches(basename)) resultController.add(entity);
338338

339339
children.forEach((sequence, child) {
@@ -368,7 +368,7 @@ class _ListTreeNode {
368368
if (isRecursive) {
369369
return new Directory(dir)
370370
.listSync(recursive: true, followLinks: followLinks)
371-
.where((entity) => _matches(entity.path.substring(dir.length + 1)));
371+
.where((entity) => _matches(p.relative(entity.path, from: dir)));
372372
}
373373

374374
// Don't spawn extra [Directory.listSync] calls when we already know exactly
@@ -383,7 +383,7 @@ class _ListTreeNode {
383383
return new Directory(dir).listSync(followLinks: followLinks)
384384
.expand((entity) {
385385
var entities = [];
386-
var basename = entity.path.substring(dir.length + 1);
386+
var basename = p.relative(entity.path, from: dir);
387387
if (_matches(basename)) entities.add(entity);
388388
if (entity is! Directory) return entities;
389389

test/glob_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:glob/glob.dart';
6+
import 'package:path/path.dart' as p;
67
import 'package:test/test.dart';
78

89
void main() {

test/list_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,19 @@ void main() {
275275
])));
276276
});
277277

278+
// Regression test for #4.
279+
test("lists an absolute case-insensitive glob", () {
280+
expect(schedule(() {
281+
var pattern = separatorToForwardSlash(
282+
p.absolute(p.join(sandbox, 'foo/Baz/**')));
283+
284+
return list(pattern, caseSensitive: false);
285+
}), completion(unorderedEquals([
286+
p.join("foo", "baz", "bang"),
287+
p.join("foo", "baz", "qux")
288+
])));
289+
});
290+
278291
test("lists a subdirectory that sometimes exists", () {
279292
d.dir("top", [
280293
d.dir("dir1", [

0 commit comments

Comments
 (0)