You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing string literals to external commands, any surrounding quotes are included in the resulting Expr::String. However, when passing a list of string literals using the spread operator, any surrounding quotes are NOT included in the resulting Expr::String.
How to reproduce
Add a dbg!(call) to the run() function in crates\nu-command\src\system\run_external.rs.
Currently run_external gets special treatment so that strings retain their surrounding quotes. The quotes are then trimmed within run_external so it can use the quotes to decide whether to perform glob/tilde expansions or not.
I think this is not a good solution, for several reason:
It duplicates the quote-striping logic. The parser can strip quotes just fine; we shouldn't need to do it again.
It provides more information than needed. run_external only needs to know one bit of information: whether the string was evaluated from an unquoted/backtick-quoted string literal. That information can be provided as a boolean.
It introduces invalid states. "Make invalid states impossible to represent" is generally a good design criteria. Keeping surrounding quotes means that we allow unbalanced quotes to be represented.
run_external is not the only command that needs to handle expansions. We should cover the use cases of other commands too, like ls and rm.
My ideal solution would be to change Value::String into something like this:
Various eval() functions should set bare to true if and only if it was evaluated from an unquoted/backtick-quoted string literal. This way, commands that want to handle expansions can do it without ever touching the syntax tree.
While we're at it, let's also remove the Value::Glob variant. The proposed Value::String variant is sufficient to cover all use cases.
I'm currently doing a full-rewrite of the run_external module to improve readability (Issue #6011). I'll finish the rewrite regardless of whether we change anything or not, but it is a good opportunity to revisit some of our design decisions.
To be fair, we don't have to be consistent, but our current implementation feels more like a hack than a proper solution. So this is technically not a bug, just something I want to bring into attention.
Maybe I don't understand what you're saying because I'd argue that we indeed have to be consistent. If the user is going to opt-in to globbing or expansion, they have to know how to do it and that means it needs to have some level of consistency, otherwise it's a confusing mess.
The current behavior is consistent for the user (bare-strings/backticks = globbing/expansion). It's only inconsistent for the developer (i.e. the current me), who has to handle strings differently based on where they came from.
Describe the bug
When passing string literals to external commands, any surrounding quotes are included in the resulting
Expr::String
. However, when passing a list of string literals using the spread operator, any surrounding quotes are NOT included in the resultingExpr::String
.How to reproduce
dbg!(call)
to therun()
function incrates\nu-command\src\system\run_external.rs
.^ls "foo" ...[ "bar" ]
Here's the output:
Expected behavior
Currently
run_external
gets special treatment so that strings retain their surrounding quotes. The quotes are then trimmed withinrun_external
so it can use the quotes to decide whether to perform glob/tilde expansions or not.I think this is not a good solution, for several reason:
run_external
only needs to know one bit of information: whether the string was evaluated from an unquoted/backtick-quoted string literal. That information can be provided as a boolean.run_external
is not the only command that needs to handle expansions. We should cover the use cases of other commands too, likels
andrm
.My ideal solution would be to change
Value::String
into something like this:Various
eval()
functions should setbare
to true if and only if it was evaluated from an unquoted/backtick-quoted string literal. This way, commands that want to handle expansions can do it without ever touching the syntax tree.While we're at it, let's also remove the
Value::Glob
variant. The proposedValue::String
variant is sufficient to cover all use cases.I'm currently doing a full-rewrite of the
run_external
module to improve readability (Issue #6011). I'll finish the rewrite regardless of whether we change anything or not, but it is a good opportunity to revisit some of our design decisions.Screenshots
No response
Configuration
Additional context
No response
The text was updated successfully, but these errors were encountered: