-
-
Notifications
You must be signed in to change notification settings - Fork 60
feat: Add shell-style quoting and escaping to edit and run commands #1993
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
base: master
Are you sure you want to change the base?
Conversation
Allows specifying a custom editor command with quoted spaces
`${CRATE_ROOT}` and `${GPR_FILE}` are still replaced directly, not
using parameter expansion.
The argument to `alr run -a` has been changed to use the same quoting
rules as `alr edit` instead of using the OS-specific rules provided by
`GNAT.OS_Lib.Argument_String_To_List`.
Quoting and token recognition uses the behavior for the shell command
language from the POSIX.1-2024 standard with a few changes:
- [2.2.2 Single-Quotes](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_02_02)
- No changes
- [2.2.3 Double-Quotes](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_02_02)
- The dollar-sign is not used for parameter expansion, command
substitution, or arithmetic expansion
- The backquote is not used for command substitution
- The backslash is an escape character within double quotes only when
immediately followed by `\` or `"`
- [2.3 Token Recognition](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_03)
- Here-documents are not supported
- Parameter expansion, command substitution, and arithmetic expansion
are not supported
- Comments are not supported
- Alias substitution is not supported
mosteo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A neat improvement. Only, see the comment about the duplicated Spawn_Raw.
Replaced the original call to `Alr.OS_Lib.Spawn_Raw` with a call to `Alire.OS_Lib.Subprocess.Spawn_Raw` to reduce duplication.
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
|
Ideally we would need a Python test for the end-user behavior. @Mivirl, are you able/willing to do it? |
aa2ff11 to
7601e44
Compare
mosteo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests, Mivirl. Only minor comments about one of them.
I'm not sure why the Windows test is failing. There's this curious effect where the last 'e' from example is disappearing:
https://github.com/alire-project/alire/actions/runs/18571537329/job/52946369421?pr=1993#step:17:1581
|
Thanks for the feedback!
Not sure why that's happening either. I don't currently have a windows environment ready to debug it, but I'm going to set one up so I can figure it out. |
|
By default, Windows GNAT does some postprocessing on command line arguments. I don't know if it's functioning as intended, but the handling of quotes is decidedly weird. Adding Do_Argv_Expansion : Integer := 0;
pragma Export (C, Do_Argv_Expansion, "__gnat_do_argv_expansion");to the declarative part of |
Thanks, that's good to know Just adding reference links below to a few commits involving this feature as I'm looking into it: |
7601e44 to
e6546e8
Compare
Thanks! I've added this to I've also submitted a bug report for GNAT about the disappearing 'e'. |
|
Looks good to me. @Seb-MCaw, since you seem familiar with these issues, any final comment? |
Not at all; this is the first time I've encountered this argument expansion behaviour. The PR looks good to me (except for the very minor detail that It's fortunate we've run into this, though, since it raises the wider issue of I guess this at least needs to be documented somewhere, if not disabled? Edit: On closer inspection, the Nonetheless, this is Windows-only, and isn't mentioned in our documentation as far as I'm aware. |
For the disabling, do you mean with |
Yes; that's the only way I'm aware of.
Obviously this would disable wildcard expansion etc. for all |
|
I think we would be better served by not having unsuspected expansions done for us. I suppose this comes from Windows where the shell is not doing the expansion? Frustration noises. |
Addresses #1314
Allows specifying a custom editor command with quoted spaces
${CRATE_ROOT}and${GPR_FILE}are still replaced directly, not using parameter expansion.The argument to
alr run -ahas been changed to use the same quoting rules asalr editinstead of using the OS-specific rules provided byGNAT.OS_Lib.Argument_String_To_List.Quoting and token recognition uses the behavior for the shell command language from the POSIX.1-2024 standard with a few changes:
\or"PR creation checklist
doc/user-changes.mdhas been updated, if there are user-visible changes.doc/catalog-format-spec.mdhas been updated, if applicable.BREAKING.mdhas been updated for major changes inalr, minor/major in catalog format.