Preserve path separator in `pub add` with absolute path (#4535)
diff --git a/lib/src/source/path.dart b/lib/src/source/path.dart index 0125d85..46b6981 100644 --- a/lib/src/source/path.dart +++ b/lib/src/source/path.dart
@@ -79,9 +79,11 @@ return PackageRef( name, PathDescription( - p.normalize( - p.join(p.absolute(containingDescription.path), description), - ), + isRelative + ? p.normalize( + p.join(p.absolute(containingDescription.path), description), + ) + : description, isRelative, ), );
diff --git a/test/add/common/add_test.dart b/test/add/common/add_test.dart index 15e8be6..8457d86 100644 --- a/test/add/common/add_test.dart +++ b/test/add/common/add_test.dart
@@ -2,11 +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:convert'; import 'dart:io' show File; import 'package:path/path.dart' as p; import 'package:pub/src/exit_codes.dart' as exit_codes; import 'package:test/test.dart'; +import 'package:test_descriptor/test_descriptor.dart'; import 'package:yaml/yaml.dart'; import '../../descriptor.dart' as d; @@ -1182,4 +1184,26 @@ server.serve('foo', '2.0.0'); await pubAdd(args: ['foo', '--offline']); }); + + test('Uses given path for absolute paths', () async { + await d.dir('foo', [d.libPubspec('foo', '1.0.0')]).create(); + + await d.appDir(dependencies: {}).create(); + + // Explicitly add using a forward slash in absolute path. + // This should be preserved in the pubspec.yaml, even on windows. + await pubAdd( + args: [ + 'foo:${json.encode({'path': '$sandbox/foo'})}', + ], + ); + + await d + .appDir( + dependencies: { + 'foo': {'path': '$sandbox/foo'}, + }, + ) + .validate(); + }); }