Skip to content
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

On powershell pub add given examples fails when yaml contain double quotes #4470

Open
AlexV525 opened this issue Dec 13, 2024 · 15 comments · May be fixed by #4472
Open

On powershell pub add given examples fails when yaml contain double quotes #4470

AlexV525 opened this issue Dec 13, 2024 · 15 comments · May be fixed by #4472
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@AlexV525
Copy link

AlexV525 commented Dec 13, 2024

Environment

  • Dart version (run dart --version): Dart SDK version: 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "windows_x64"

Problem

As the help message of pub add tells:

Add packages with specific constraints or other sources by giving a descriptor
after a colon.

For example:
  * Add a path dependency:
    `dart pub add 'foo:{"path":"../foo"}'`

But when I run dart pub add 'foundation:{"path":"../foundation"}' it tells:

The only allowed prefixes are "dev:" and "override:"

And without the single quotes:

Because app depends on foundation from unknown source "path:../foundation", version solving failed.

Changing to dart pub add foundation:{"path": "../foundation"} (without the single quotes and extra space between : and "..) will solve the issue.

Expected behavior

The command should execute without exceptions.

Actual behavior

The command will fail to execute.

Logs

> dart pub add 'foundation:{"path":"../foundation"}'
Usage: pub add [options] [<section>:]<package>[:descriptor]
       [<section>:]<package2>[:descriptor] ...]
-h, --help               Print this usage information.
    --[no-]offline       Use cached packages instead of accessing the network.
-n, --dry-run            Report what dependencies would change but don't change
                         any.
    --[no-]precompile    Build executables in immediate dependencies.
-C, --directory=<dir>    Run this in the directory <dir>.

Run "pub help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-add for detailed documentation.

Process finished with exit code 64

> dart pub add foundation:{"path":"../foundation"}
Because app depends on foundation from unknown source "path:../foundation", version solving failed.

> dart pub add foundation:{"path": "../foundation"}
Resolving dependencies...
Downloading packages...
@sigurdm sigurdm added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Dec 13, 2024
@AlexV525
Copy link
Author

AlexV525 commented Dec 13, 2024

Investigated and it seems the issue was caused by the yaml package where path:../foo will not be recognized as a valid source. This looks like an expected behavior so we might want to change the help message to include the space.

However we can remove the leading and the trailing single quote to solve the first phase of the issue.

@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

Ah - I thought it was our parsing that was broken!

Thanks for investigating. Surely we should fix the help message.

@AlexV525
Copy link
Author

AlexV525 commented Dec 13, 2024

What I was experimenting is update the match from our end to give a lenient input. Something like replace ([a-z]+):(.*) to $1: $2

@AlexV525 AlexV525 linked a pull request Dec 13, 2024 that will close this issue
1 task
@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

Hmm could you try again with the single quotes. I cannot reproduce your error:

$ dart pub add 'foundation:{"path":"../foundation"}'
Because pana depends on foundation from path which doesn't exist (could not find package foundation at
  "../foundation"), version solving failed.

Seems to parse alright...

@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

Ahh - I think the problem might be that you are on windows - what shell are you using?

@AlexV525
Copy link
Author

Ahh - I think the problem might be that you are on windows - what shell are you using?

Yeah I'm using the PoweShell on Windows 11.

@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

Here are rules for cmd https://stackoverflow.com/questions/7760545/escape-double-quotes-in-parameter
And for powershell: https://serverfault.com/questions/47811/what-is-the-literal-escape-character-in-powershell

Are you running dart from a flutter install? I think that goes through a batch file...

@AlexV525
Copy link
Author

Are you running dart from a flutter install? I think that goes through a batch file...

Initially yes. Running flutter pub add and dart pub add gives different results when parsing the arguments.

@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

How about $FLUTTER_ROOT/bin/cache/dart-sdk/bin/dart pub add

@AlexV525
Copy link
Author

How about $FLUTTER_ROOT/bin/cache/dart-sdk/bin/dart pub add

The issue command was tested through this as I exported the Dart SDK path from the Flutter install.

> which dart
/x/SDK/flutter/bin/dart

@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

I'm just trying to find out where in the pipeline the quotation gets broken.
I fired up a windows VM, and it seems it is powershell, not the batch script swallowing the quotes:

//test.dart
main(List<String> args) {
  print('${args[0]}');
}
PS C:\Users\sigurdm\~\blah> dart test.dart 'foo:{"path":"abc"}'
foo:{path:abc}

It seems like powershell always needs a back-tick ` before each " character or https://stackoverflow.com/a/44843143/4809566

Maybe we just update the examples to include the space, and things "work" on powershell (cmd is still an issue though)

@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

@jonasfj maybe passing yaml/json on the commandline was a mistake. Seems like there is no good way to pass quotes across powershell, cmd and bash...

@sigurdm sigurdm changed the title [add] Unable to recognize {$source:$dest} when there is no space between : and $dest On powershell pub add given examples fails when yaml contain double quotes Dec 13, 2024
@AlexV525
Copy link
Author

I'm just trying to find out where in the pipeline the quotation gets broken. I fired up a windows VM, and it seems it is powershell, not the batch script swallowing the quotes:

//test.dart
main(List<String> args) {
  print('${args[0]}');
}
PS C:\Users\sigurdm\~\blah> dart test.dart 'foo:{"path":"abc"}'
foo:{path:abc}

And cmd reports 'foo:{path:abc}', which https://github.com/dart-lang/pub/pull/4472/files#diff-b498037f9dbf4794c64e3cf63a15c4ef905c864ac1799141954c4f05e8cda53cR384-R387 should take place.

@AlexV525
Copy link
Author

For cmd I shall use 'foo:{\"path\":\"../foo\"}'. The IntelliJ IDEA runs on a cmd instance...

@sigurdm
Copy link
Contributor

sigurdm commented Dec 13, 2024

The point is, that dart should receive the string foo:{"path":"abc"} in bash that is done by using single quotes: 'foo:{"path":"abc"}'.

In cmd you can tripple the quotes foo:{"""path""":"""abc"""}
In powershell you can escape the quotes: "foo:{\`"path\`":\`"abc\`"}"

None of those are desirable.

Now, because we are parsing yaml and not json, we can drop the quotes, but insert a space: foo:{path: foo}. Maybe we should fix the examples to be like:

dart pub add "foo:{path: abc/de}"

That should work on cmd, powershell and bash (as long as the path-name doesn't contain really weird characters)

which https://github.com/dart-lang/pub/pull/4472/files#diff-b498037f9dbf4794c64e3cf63a15c4ef905c864ac1799141954c4f05e8cda53cR384-R387 should take place.

We don't want to patch the string up after the fact to somehow become valid yaml. It is not a general solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants