Skip to content

Commit 61329c2

Browse files
authored
Preserve path separator in pub add with absolute path (#4535)
1 parent e44a3eb commit 61329c2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/src/source/path.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ class PathSource extends Source {
7979
return PackageRef(
8080
name,
8181
PathDescription(
82-
p.normalize(
83-
p.join(p.absolute(containingDescription.path), description),
84-
),
82+
isRelative
83+
? p.normalize(
84+
p.join(p.absolute(containingDescription.path), description),
85+
)
86+
: description,
8587
isRelative,
8688
),
8789
);

test/add/common/add_test.dart

+24
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:convert';
56
import 'dart:io' show File;
67

78
import 'package:path/path.dart' as p;
89
import 'package:pub/src/exit_codes.dart' as exit_codes;
910
import 'package:test/test.dart';
11+
import 'package:test_descriptor/test_descriptor.dart';
1012
import 'package:yaml/yaml.dart';
1113

1214
import '../../descriptor.dart' as d;
@@ -1182,4 +1184,26 @@ dependency_overrides:
11821184
server.serve('foo', '2.0.0');
11831185
await pubAdd(args: ['foo', '--offline']);
11841186
});
1187+
1188+
test('Uses given path for absolute paths', () async {
1189+
await d.dir('foo', [d.libPubspec('foo', '1.0.0')]).create();
1190+
1191+
await d.appDir(dependencies: {}).create();
1192+
1193+
// Explicitly add using a forward slash in absolute path.
1194+
// This should be preserved in the pubspec.yaml, even on windows.
1195+
await pubAdd(
1196+
args: [
1197+
'foo:${json.encode({'path': '$sandbox/foo'})}',
1198+
],
1199+
);
1200+
1201+
await d
1202+
.appDir(
1203+
dependencies: {
1204+
'foo': {'path': '$sandbox/foo'},
1205+
},
1206+
)
1207+
.validate();
1208+
});
11851209
}

0 commit comments

Comments
 (0)