Skip to content

Use forward slashes in paths when using path dependencies from git dependencies #4315

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

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions lib/src/source/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ class PathSource extends Source {
'"$description" is an absolute path, it can\'t be referenced from a git pubspec.',
);
}
final resolvedPath = p.url.joinAll([
containingDescription.path,
...p.posix.split(dir),
]);
if (!p.isWithin('.', resolvedPath)) {
final resolvedPath = p.url.normalize(
p.url.joinAll([
containingDescription.path,
...p.posix.split(dir),
]),
);
if (!(p.isWithin('.', resolvedPath) || p.equals('.', resolvedPath))) {
throw FormatException(
'the path "$description" cannot refer outside the git repository $resolvedPath.',
);
Expand All @@ -118,12 +120,7 @@ class PathSource extends Source {
url: containingDescription.url,
relative: containingDescription.relative,
ref: containingDescription.ref,
path: p.normalize(
p.join(
containingDescription.path,
dir,
),
),
path: resolvedPath,
),
);
} else if (containingDescription is HostedDescription) {
Expand Down
51 changes: 49 additions & 2 deletions test/get/git/check_out_transitive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:pub/src/exit_codes.dart' as exit_codes;
import 'package:pub/src/exit_codes.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

import '../../descriptor.dart' as d;
import '../../test_pub.dart';
Expand Down Expand Up @@ -99,17 +102,61 @@ void main() {
test('can have relative path dependencies transitively from Git', () async {
ensureGit();

await d.git('foo.git', [
d.dir('pkgs', [
d.dir('foo', [
d.libPubspec(
'foo',
'1.0.0',
deps: {
'bar': {'path': '../bar'},
},
),
]),
d.dir('bar', [d.libPubspec('bar', '1.0.0')]),
]),
]).create();

await d.appDir(
dependencies: {
'foo': {
'git': {
'url': p
.toUri(p.absolute(d.sandbox, appPath, '../foo.git'))
.toString(),
'path': 'pkgs/foo',
},
},
},
).create();

await pubGet();
final lockFile = loadYaml(
File(p.join(d.sandbox, appPath, 'pubspec.lock')).readAsStringSync(),
);
expect(
lockFile['packages']['bar']['description']['path'],
'pkgs/bar',
reason: 'Use forward slashes for path',
);
});

test(
'can have relative path dependencies to the repo root dir transitively from Git',
() async {
ensureGit();

await d.git('foo.git', [
d.dir('foo', [
d.libPubspec(
'foo',
'1.0.0',
deps: {
'bar': {'path': '../bar'},
'bar': {'path': '..'},
},
),
]),
d.dir('bar', [d.libPubspec('bar', '1.0.0')]),
d.libPubspec('bar', '1.0.0'),
]).create();

await d.appDir(
Expand Down
Loading