mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 23:23:12 +01:00
Externals shouldn't expand aliases (#4889)
This commit is contained in:
parent
18067138aa
commit
66e736dab4
@ -436,14 +436,14 @@ fn test_count_counts_codepoints() {
|
|||||||
|
|
||||||
let counters = [Counter::CodePoints];
|
let counters = [Counter::CodePoints];
|
||||||
|
|
||||||
let counts = uwc_count(&counters[..], &one);
|
let counts = uwc_count(&counters[..], one);
|
||||||
|
|
||||||
let mut correct_counts = BTreeMap::new();
|
let mut correct_counts = BTreeMap::new();
|
||||||
correct_counts.insert(Counter::CodePoints, 1);
|
correct_counts.insert(Counter::CodePoints, 1);
|
||||||
|
|
||||||
assert_eq!(correct_counts, counts);
|
assert_eq!(correct_counts, counts);
|
||||||
|
|
||||||
let counts = uwc_count(&counters[..], &two);
|
let counts = uwc_count(&counters[..], two);
|
||||||
|
|
||||||
let mut correct_counts = BTreeMap::new();
|
let mut correct_counts = BTreeMap::new();
|
||||||
correct_counts.insert(Counter::CodePoints, 2);
|
correct_counts.insert(Counter::CodePoints, 2);
|
||||||
|
@ -210,6 +210,8 @@ pub fn parse_external_call(
|
|||||||
spans: &[Span],
|
spans: &[Span],
|
||||||
expand_aliases_denylist: &[usize],
|
expand_aliases_denylist: &[usize],
|
||||||
) -> (Expression, Option<ParseError>) {
|
) -> (Expression, Option<ParseError>) {
|
||||||
|
trace!("parse external");
|
||||||
|
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
|
|
||||||
let head_contents = working_set.get_span_contents(spans[0]);
|
let head_contents = working_set.get_span_contents(spans[0]);
|
||||||
@ -225,33 +227,6 @@ pub fn parse_external_call(
|
|||||||
|
|
||||||
let head_contents = working_set.get_span_contents(head_span).to_vec();
|
let head_contents = working_set.get_span_contents(head_span).to_vec();
|
||||||
|
|
||||||
// If the word is an alias, expand it and re-parse the expression
|
|
||||||
if let Some(alias_id) = working_set.find_alias(&head_contents) {
|
|
||||||
let expansion = working_set.get_alias(alias_id);
|
|
||||||
let expansion_span = span(expansion);
|
|
||||||
|
|
||||||
let orig_span = span(&[spans[0], spans[0]]);
|
|
||||||
let mut new_spans: Vec<Span> = expansion.to_vec();
|
|
||||||
if spans.len() > 1 {
|
|
||||||
new_spans.extend(&spans[1..])
|
|
||||||
}
|
|
||||||
|
|
||||||
let expand_aliases_denylist = if let Some(alias_id) = working_set.find_alias(&head_contents)
|
|
||||||
{
|
|
||||||
let mut expand_aliases_denylist = expand_aliases_denylist.to_vec();
|
|
||||||
expand_aliases_denylist.push(alias_id);
|
|
||||||
expand_aliases_denylist
|
|
||||||
} else {
|
|
||||||
expand_aliases_denylist.to_vec()
|
|
||||||
};
|
|
||||||
|
|
||||||
let (mut result, err) =
|
|
||||||
parse_external_call(working_set, &new_spans, &expand_aliases_denylist);
|
|
||||||
result.replace_span(working_set, expansion_span, orig_span);
|
|
||||||
|
|
||||||
return (result, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
let head = if head_contents.starts_with(b"$") || head_contents.starts_with(b"(") {
|
let head = if head_contents.starts_with(b"$") || head_contents.starts_with(b"(") {
|
||||||
@ -939,6 +914,7 @@ pub fn parse_call(
|
|||||||
comments: vec![],
|
comments: vec![],
|
||||||
parts: new_spans.clone(),
|
parts: new_spans.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (mut result, err) =
|
let (mut result, err) =
|
||||||
parse_builtin_commands(working_set, &lite_command, &expand_aliases_denylist);
|
parse_builtin_commands(working_set, &lite_command, &expand_aliases_denylist);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user