Skip to content

Commit 06ea336

Browse files
committed
windows-fixes
1 parent 48e1986 commit 06ea336

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

packages/devtools_shared/test/server/file_system_test.dart

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:convert';
66

77
import 'package:devtools_shared/src/server/file_system.dart' hide fileSystem;
88
import 'package:file/memory.dart';
9+
import 'package:path/path.dart' as path;
910
import 'package:test/test.dart';
1011

1112
void main() {
@@ -25,31 +26,50 @@ void main() {
2526
// stay confined to the ~/.flutter-devtools/ directory.
2627

2728
test('rejects absolute paths', () {
28-
// path.join() discards the base directory when its second argument is
29+
final root = path.style == .windows ? 'C:\\' : '/';
30+
// `path.join()` discards the base directory when its second argument is
2931
// absolute, so an absolute path would otherwise escape the DevTools
3032
// directory and read an arbitrary file on disk.
31-
expect(fs.devToolsFileFromPath('/etc/passwd'), isNull);
32-
expect(fs.devToolsFileFromPath('/absolute/path/to/file.json'), isNull);
33+
expect(
34+
fs.devToolsFileFromPath(path.join('${root}etc', 'passwd')),
35+
isNull,
36+
);
37+
expect(
38+
fs.devToolsFileFromPath(
39+
path.join('${root}absolute', 'path', 'to', 'file.json'),
40+
),
41+
isNull,
42+
);
3343
});
3444

3545
test('rejects paths containing ".."', () {
3646
expect(fs.devToolsFileFromPath('..'), isNull);
37-
expect(fs.devToolsFileFromPath('../../../etc/passwd'), isNull);
38-
expect(fs.devToolsFileFromPath('subdir/../../escape.json'), isNull);
47+
expect(
48+
fs.devToolsFileFromPath(path.join('..', '..', '..', 'etc', 'passwd')),
49+
isNull,
50+
);
51+
expect(
52+
fs.devToolsFileFromPath(
53+
path.join('subdir', '..', '..', 'escape.json'),
54+
),
55+
isNull,
56+
);
3957
});
4058
});
4159

4260
test('returns file when path is valid and file exists', () {
43-
final devToolsDir = FileSystemExtension.devToolsDir;
44-
final testFile = fs.file('$devToolsDir/sub/file.json')
45-
..createSync(recursive: true);
61+
final testFile = fs.file(
62+
path.join(FileSystemExtension.devToolsDir, 'sub', 'file.json'),
63+
)..createSync(recursive: true);
4664

47-
final file = fs.devToolsFileFromPath('sub/file.json')!;
65+
final file = fs.devToolsFileFromPath(path.join('sub', 'file.json'))!;
4866
expect(file.path, testFile.path);
4967
});
5068

5169
test('returns null when path is valid but file does not exist', () {
52-
final file = fs.devToolsFileFromPath('sub/non_existent.json');
70+
final file = fs.devToolsFileFromPath(
71+
path.join('sub', 'non_existent.json'),
72+
);
5373
expect(file, isNull);
5474
});
5575
});
@@ -70,17 +90,16 @@ void main() {
7090
});
7191

7292
test('returns null if file is not json', () {
73-
final devToolsDir = FileSystemExtension.devToolsDir;
74-
fs.file('$devToolsDir/test.txt')
93+
fs.file(path.join(FileSystemExtension.devToolsDir, 'test.txt'))
7594
..createSync(recursive: true)
7695
..writeAsStringSync('hello');
7796
expect(fs.devToolsFileAsJson('test.txt'), isNull);
7897
});
7998

8099
test('returns json content with lastModifiedTime', () {
81-
final devToolsDir = FileSystemExtension.devToolsDir;
82-
final file = fs.file('$devToolsDir/test.json')
83-
..createSync(recursive: true);
100+
final file = fs.file(
101+
path.join(FileSystemExtension.devToolsDir, 'test.json'),
102+
)..createSync(recursive: true);
84103
file.writeAsStringSync('{"key": "value"}');
85104

86105
final jsonStr = fs.devToolsFileAsJson('test.json')!;

packages/devtools_shared/test/server/persistent_properties_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:convert';
77
import 'package:devtools_shared/src/server/file_system.dart';
88
import 'package:file/file.dart';
99
import 'package:file/memory.dart';
10+
import 'package:path/path.dart' as path;
1011
import 'package:test/test.dart';
1112

1213
void main() {
@@ -32,7 +33,7 @@ void main() {
3233
properties['key1'] = 'value1';
3334
properties['key2'] = 'value2';
3435

35-
final file = fs.file('${tempDir.path}/$storeName');
36+
final file = fs.file(path.join(tempDir.path, storeName));
3637
expect(file.existsSync(), isTrue);
3738

3839
var content = file.readAsStringSync();

0 commit comments

Comments
 (0)