diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 7dfccf7bad..3416e538df 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -228,6 +228,8 @@ fn parse_external_arg(working_set: &mut StateWorkingSet, span: Span) -> External ExternalArgument::Regular(parse_dollar_expr(working_set, span)) } else if contents.starts_with(b"[") { ExternalArgument::Regular(parse_list_expression(working_set, span, &SyntaxShape::Any)) + } else if contents.starts_with(b"r#") { + ExternalArgument::Regular(parse_raw_string(working_set, span)) } else if contents.len() > 3 && contents.starts_with(b"...") && (contents[3] == b'$' || contents[3] == b'[' || contents[3] == b'(') diff --git a/crates/nu-parser/tests/test_parser.rs b/crates/nu-parser/tests/test_parser.rs index e73f0f2e02..9b8ae94317 100644 --- a/crates/nu-parser/tests/test_parser.rs +++ b/crates/nu-parser/tests/test_parser.rs @@ -1,6 +1,6 @@ use nu_parser::*; use nu_protocol::{ - ast::{Argument, Call, Expr, PathMember, Range}, + ast::{Argument, Call, Expr, ExternalArgument, PathMember, Range}, engine::{Command, EngineState, Stack, StateWorkingSet}, ParseError, PipelineData, ShellError, Signature, Span, SyntaxShape, }; @@ -926,6 +926,28 @@ mod string { assert!(working_set.parse_errors.is_empty()); } } + + #[test] + fn parse_raw_string_as_external_argument() { + let engine_state = EngineState::new(); + let mut working_set = StateWorkingSet::new(&engine_state); + + let block = parse(&mut working_set, None, b"^echo r#'text'#", true); + + assert!(working_set.parse_errors.is_empty()); + assert_eq!(block.len(), 1); + let pipeline = &block.pipelines[0]; + assert_eq!(pipeline.len(), 1); + let element = &pipeline.elements[0]; + assert!(element.redirection.is_none()); + if let Expr::ExternalCall(_, args) = &element.expr.expr { + if let [ExternalArgument::Regular(expr)] = args.as_ref() { + assert_eq!(expr.expr, Expr::RawString("text".into())); + return; + } + } + panic!("wrong expression: {:?}", element.expr.expr) + } } #[rstest] diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index 88d443e4fd..3cbed5a124 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -314,6 +314,7 @@ mod external_words { use super::nu; use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::{pipeline, playground::Playground}; + #[test] fn relaxed_external_words() { let actual = nu!(" @@ -323,6 +324,12 @@ mod external_words { assert_eq!(actual.out, "joturner@foo.bar.baz"); } + #[test] + fn raw_string_as_external_argument() { + let actual = nu!("nu --testbin cococo r#'asdf'#"); + assert_eq!(actual.out, "asdf"); + } + //FIXME: jt: limitation in testing - can't use single ticks currently #[ignore] #[test]