Skip to content

Commit 9f2ddc0

Browse files
authored
Use uris for paths in git source descriptions (#3063)
1 parent 97a0033 commit 9f2ddc0

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

lib/src/source/git.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class GitSource extends Source {
142142
return {'relative': relative, 'url': url};
143143
}
144144

145+
/// Returns [path] normalized.
146+
///
145147
/// Throws a [FormatException] if [path] isn't a relative url or null.
146148
String _validatedPath(dynamic path) {
147149
path ??= '.';
@@ -161,7 +163,7 @@ class GitSource extends Source {
161163
"The 'path' field of the description must not reach outside the "
162164
'repository.');
163165
}
164-
return p.normalize(parsed.toString());
166+
return p.url.normalize(parsed.toString());
165167
}
166168

167169
/// If [description] has a resolved ref, print it out in short-form.
@@ -352,7 +354,7 @@ class BoundGitSource extends CachedSource {
352354

353355
return Package.load(
354356
id.name,
355-
p.join(revisionCachePath, id.description['path']),
357+
p.join(revisionCachePath, p.fromUri(id.description['path'])),
356358
systemCache.sources);
357359
});
358360
}

test/get/git/path_test.dart

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import 'package:path/path.dart' as p;
88
import 'package:pub/src/io.dart';
9+
import 'package:pub/src/lock_file.dart';
10+
import 'package:pub/src/source_registry.dart';
911
import 'package:test/test.dart';
1012

1113
import '../../descriptor.dart' as d;
@@ -47,14 +49,14 @@ void main() {
4749

4850
var repo = d.git('foo.git', [
4951
d.dir('sub', [
50-
d.dir('dir', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')])
52+
d.dir('dir%', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')])
5153
])
5254
]);
5355
await repo.create();
5456

5557
await d.appDir({
5658
'sub': {
57-
'git': {'url': '../foo.git', 'path': 'sub/dir'}
59+
'git': {'url': '../foo.git', 'path': 'sub/dir%25'}
5860
}
5961
}).create();
6062

@@ -65,15 +67,65 @@ void main() {
6567
d.dir('cache', [d.gitPackageRepoCacheDir('foo')]),
6668
d.hashDir('foo', [
6769
d.dir('sub', [
68-
d.dir('dir', [d.libDir('sub', '1.0.0')])
70+
d.dir('dir%', [d.libDir('sub', '1.0.0')])
6971
])
7072
])
7173
])
7274
]).validate();
7375

7476
await d.appPackagesFile({
75-
'sub': pathInCache('git/foo-${await repo.revParse('HEAD')}/sub/dir')
77+
'sub': pathInCache('git/foo-${await repo.revParse('HEAD')}/sub/dir%25')
7678
}).validate();
79+
80+
final lockFile = LockFile.load(
81+
p.join(d.sandbox, appPath, 'pubspec.lock'), SourceRegistry());
82+
83+
expect(lockFile.packages['sub'].description['path'], 'sub/dir%25',
84+
reason: 'use uris to specify the path relative to the repo');
85+
});
86+
87+
test('depends on a package in a deep subdirectory, non-relative uri',
88+
() async {
89+
ensureGit();
90+
91+
var repo = d.git('foo.git', [
92+
d.dir('sub', [
93+
d.dir('dir%', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')])
94+
])
95+
]);
96+
await repo.create();
97+
98+
await d.appDir({
99+
'sub': {
100+
'git': {
101+
'url': p.toUri(p.join(d.sandbox, 'foo.git')).toString(),
102+
'path': 'sub/dir%25'
103+
}
104+
}
105+
}).create();
106+
107+
await pubGet();
108+
109+
await d.dir(cachePath, [
110+
d.dir('git', [
111+
d.dir('cache', [d.gitPackageRepoCacheDir('foo')]),
112+
d.hashDir('foo', [
113+
d.dir('sub', [
114+
d.dir('dir%', [d.libDir('sub', '1.0.0')])
115+
])
116+
])
117+
])
118+
]).validate();
119+
120+
await d.appPackagesFile({
121+
'sub': pathInCache('git/foo-${await repo.revParse('HEAD')}/sub/dir%25')
122+
}).validate();
123+
124+
final lockFile = LockFile.load(
125+
p.join(d.sandbox, appPath, 'pubspec.lock'), SourceRegistry());
126+
127+
expect(lockFile.packages['sub'].description['path'], 'sub/dir%25',
128+
reason: 'use uris to specify the path relative to the repo');
77129
});
78130

79131
test('depends on multiple packages in subdirectories', () async {

0 commit comments

Comments
 (0)