dart-lang / pub

The pub command line tool
https://dart.dev/tools/pub/cmd
BSD 3-Clause "New" or "Revised" License
1.05k stars 230 forks source link

pub upgrade fails if url is specified in git@github.com format for authentication by ssh #3377

Closed koji-1009 closed 2 years ago

koji-1009 commented 2 years ago

Environment

Problem

If you specify a git repository for dependency in the form git@github.com:rrousselGit/provider.git, then Succeeds in flutter's stable channel, but fails in flutter's master channel.

The operation can be reproduced by describing the dependency as follows. (The project that noticed this problem refers to a private GitHub repository that only internal members have access to.)

  provider:
    git:
      url: git@github.com:rrousselGit/provider.git
      ref: master

https://github.com/dart-lang/pub/commit/610ce7f280189f39ec411eb0a8592a191940d8d2#diff-1639c4669c428c26e68cfebd5039a33f87ba568795f2c058c303ca8528f62b77R720

In the above commit, Uri.parse is now called internally. Dart's Uri.parse throws FormatException for formats like git@github.com.

dartpad

Expected behavior

pub upgrade succeeds

Actual behavior

pub upgrade fails

--trace output

$ dart pub upgrade
Resolving dependencies... (4.0s)
Illegal scheme character (at character 4)
git@github.com:rrousselGit/provider.git
   ^
dart:core                                   Uri.parse
package:path/src/context.dart 1077:33       _parseUri
package:path/src/context.dart 1052:22       Context.prettyUri
package:path/path.dart 461:34               prettyUri
package:pub/src/source/git.dart 730:23      GitResolvedDescription.format
package:pub/src/solver/report.dart 326:40   SolveReport._writeId
package:pub/src/solver/report.dart 302:5    SolveReport._reportPackage
===== asynchronous gap ===========================
package:pub/src/solver/report.dart 114:7    SolveReport._reportChanges
===== asynchronous gap ===========================
package:pub/src/solver/report.dart 47:5     SolveReport.show
===== asynchronous gap ===========================
package:pub/src/solver/result.dart 112:5    SolveResult.showReport
===== asynchronous gap ===========================
package:pub/src/entrypoint.dart 321:7       Entrypoint.acquireDependencies
===== asynchronous gap ===========================
package:pub/src/command/upgrade.dart 123:5  UpgradeCommand._runUpgrade
===== asynchronous gap ===========================
package:pub/src/command/upgrade.dart 112:7  UpgradeCommand.runProtected
This is an unexpected error. The full log and other details are collected in:

    /Users/kojiwakamiya/.pub-cache/log/pub_log.txt

Consider creating an issue on https://github.com/dart-lang/pub/issues/new
and attaching the relevant parts of that log file.
eric8810 commented 2 years ago

I've got same issues too. looks like its dart uri scheme check limit the url's scheme, and git ssh reposity does not have one scheme.

pub version or flutter pub version: Pub 2.17.0-266.0.dev OS version: macOS Monterey Are you using the Chinese community mirror or a corporate firewall?: No

error log here:

ERR : Illegal scheme character (at character 4) git@gitlab.y5ops.com:ZENZEN/official_flutter_plugins.git ^ FINE: Exception type: FormatException ERR : dart:core Uri.parse package:path/src/context.dart 1077:33 _parseUri package:path/src/context.dart 1052:22 Context.prettyUri package:path/path.dart 461:34 prettyUri package:pub/src/source/git.dart 730:23 GitResolvedDescription.format package:pub/src/solver/report.dart 326:40 SolveReport._writeId package:pub/src/solver/report.dart 302:5 SolveReport._reportPackage ===== asynchronous gap =========================== package:pub/src/solver/report.dart 138:9 SolveReport._reportOverrides ===== asynchronous gap =========================== package:pub/src/solver/report.dart 48:5 SolveReport.show ===== asynchronous gap =========================== package:pub/src/solver/result.dart 112:5 SolveResult.showReport ===== asynchronous gap =========================== package:pub/src/entrypoint.dart 321:7 Entrypoint.acquireDependencies ===== asynchronous gap =========================== package:pub/src/command/get.dart 52:5 GetCommand.runProtected ERR : This is an unexpected error. The full log and other details are collected in:
/Users/eric8810/.pub-cache/log/pub_log.txt
Consider creating an issue on https://github.com/dart-lang/pub/issues/new
and attaching the relevant parts of that log file.

---- End log transcript ----

sigurdm commented 2 years ago

Hmm - this is indeed a regression. I wonder about the best fix. Should we just never handle the git uri with package 'Uri'?

@lrhn Would you expect Uri.parse to be able to parse something of the form: 'git@github.com:dart-lang/pub.git'?

This is what github suggests to use for cloning a repository via ssh.

jonasfj commented 2 years ago

I think it's the colon that creates problems.

eric8810 commented 2 years ago

nice & quick fix, thank you. when will this be pushed to flutter master toolchain? @sigurdm

koji-1009 commented 2 years ago

Thanks!

adamRussakMAHITL commented 2 years ago

nice fix! when and what version will it be pushed? we are facing this issue with iOS builds only (android works ok..) in version 2.13 it fails version 2.10.4 it passes.

lrhn commented 2 years ago

Good fix. I would not expect Uri.parse to be able to parse something of the form: 'git@github.com:dart-lang/pub.git'. If it did, it would have to put everything into the path, because the schema can't contain @ and the authority needs a leading //, so the only remotely valid parsing would be as a relative path. It doesn't parse as that since the grammar of relative URI references requires the first segment to not contain a : (whether it contains non-schema characters first or not).

So, not parsing as a URI, definitely never parsing as a URI with a schema, which is how I expect that it's intended.

sigurdm commented 2 years ago

@eric8810

when will this be pushed to flutter master toolchain?

It has landed in the dart sdk here: https://github.com/dart-lang/sdk/commit/557089ea5d784b9664b3e896795e81e8c580912e

It was rolled to flutter/engine here: https://github.com/flutter/engine/pull/32459

This still has to roll into the flutter/flutter . Not sure exactly the expected timing of that...

vmalyi commented 2 years ago

This still has to roll into the flutter/flutter . Not sure exactly the expected timing of that...

@sigurdm, could you please provide any updates on expected timing for merging this into flutter/flutter?

Thanks!

nicholasspencer commented 2 years ago

It looks like this might be also happening to dart pub global activate -sgit on stable?

IO  : Spawning "git clone --depth 1 git@github.com:resideo/izakaya.git /private/var/folders/0n/0qft49497gn32fqr3zqbm56h0000gn/T/pub_88uD8Z" in /Users/nicholasspencer/Development/comfort_plugins_flutter/packages/jasper_driver_platform_plugin/.
IO  : Finished git. Exit code 0.
    | Nothing output on stdout.
    | stderr:
    | | Cloning into '/private/var/folders/0n/0qft49497gn32fqr3zqbm56h0000gn/T/pub_88uD8Z'...
IO  : Deleting directory /private/var/folders/0n/0qft49497gn32fqr3zqbm56h0000gn/T/pub_88uD8Z.
ERR : Illegal scheme character (at character 4)
    | git@github.com:resideo/izakaya.git
    |    ^
FINE: Exception type: FormatException
ERR : dart:core                                    Uri.parse
    | package:path/src/context.dart 1077:33        _parseUri
    | package:path/src/context.dart 1052:22        Context.prettyUri
    | package:path/path.dart 461:34                prettyUri
    | package:pub/src/global_packages.dart 295:28  GlobalPackages._describeActive
    | package:pub/src/global_packages.dart 194:34  GlobalPackages._installInCache
    | package:pub/src/global_packages.dart 114:11  GlobalPackages.activateGit    
sigurdm commented 2 years ago

My fix was not handling all usage of git@ style uris. filed another fix - hoping to get it into dart 2.18