Skip to content

Single quotes string variable interpolation error when there is = in it #4890

Closed

Description

@hustcer

Describe the bug

Single quotes string variable interpolation error when there is = in it, double quotes works fine

How to reproduce

Run let since = '2022/03/01';let from = $'--since=($since)' you will get:

Error: nu::parser::unknown_command (link)

  × Unknown command.
   ╭─[entry #100:1:1]
 1 │ let since = '2022/03/01';let from = $'--since=($since)'
   ·                                     ─────────┬─────────
   ·                                              ╰── unknown command
   ╰────

Expected behavior

Should be the same behavior as let since = '2022/03/01';let from = $"--since=($since)"

Screenshots

No response

Configuration

key value
version 0.59.1
branch main
short_commit 66e736d
commit_hash 66e736d
commit_date 2022-03-21 22:57:48 +00:00
build_os macos-x86_64
rust_version rustc 1.59.0 (9d1b2106e 2022-02-23)
rust_channel stable-x86_64-apple-darwin
cargo_version cargo 1.59.0 (49d8809dc 2022-02-10)
pkg_version 0.59.1
build_time 2022-03-22 10:02:11 +08:00
build_rust_channel release
features dataframe, default, trash, which, zip
installed_plugins query, query json, query web, query xml

Additional context

No response

Activity

  1. added
    category:bug
    on Mar 22, 2022
  2. uasi commented on Mar 24, 2022

    @uasi
    Contributor

    Shorter reproducible example is let x = $'=':

    〉let x = $'='
    2022-03-24 07:56:17.030 AM|TRACE|nu_cli::repl            |eval source: let x = $'='
    2022-03-24 07:56:17.030 AM|TRACE|nu_cli::util            |eval_source
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |starting top-level parse
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |parsing block: LiteBlock { block: [LitePipeline { commands: [LiteCommand { comments: [], parts: [Span { start: 14001, end: 14004 }, Span { start: 14005, end: 14006 }, Span { start: 14007, end: 14008 }, Span { start: 14009, end: 14013 }] }] }] }
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |parsing: keyword(=) Expression
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |parsing: expression
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |parsing: string, with required delimiters
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |-- found $'
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |parsing: string, with required delimiters
    2022-03-24 07:56:17.030 AM|TRACE|nu_parser::parser       |-- found '
    Error: nu::parser::unknown_command (https://docs.rs/nu-parser/0.60.0/nu-parser/enum.ParseError.html#variant.UnknownCommand)
    
      × Unknown command.
       ╭─[entry #1:1:1]
     1 │ let x = $'='
       ·         ──┬─
       ·           ╰── unknown command
       ╰────
    

    EDIT: let x = '=' raises the same error.

    echo $'=' works fine, though:

    〉echo $'='
    2022-03-24 07:56:58.406 AM|TRACE|nu_cli::repl            |eval source: echo $'='
    2022-03-24 07:56:58.406 AM|TRACE|nu_cli::util            |eval_source
    2022-03-24 07:56:58.406 AM|TRACE|nu_parser::parser       |starting top-level parse
    2022-03-24 07:56:58.406 AM|TRACE|nu_parser::parser       |parsing block: LiteBlock { block: [LitePipeline { commands: [LiteCommand { comments: [], parts: [Span { start: 14001, end: 14005 }, Span { start: 14006, end: 14010 }] }] }] }
    2022-03-24 07:56:58.406 AM|TRACE|nu_parser::parser       |parsing: call
    2022-03-24 07:56:58.406 AM|TRACE|nu_parser::parser       |parsing: internal call
    2022-03-24 07:56:58.406 AM|TRACE|nu_parser::parser       |parsing: internal call (decl id: 82)
    2022-03-24 07:56:58.406 AM|TRACE|nu_parser::parser       |parsing: dollar expression
    =
    
    Configuration
    key value
    version 0.60.0
    short_commit 74af31a
    commit_hash 74af31a
    commit_date 2022-03-22 19:07:11 +00:00
    build_os macos-x86_64
    rust_version rustc 1.59.0 (9d1b2106e 2022-02-23)
    rust_channel stable-x86_64-apple-darwin
    cargo_version cargo 1.59.0 (49d8809dc 2022-02-10)
    pkg_version 0.60.0
    build_time 2022-03-22 19:23:50 +00:00
    build_rust_channel release
    features dataframe, default, trash, which, zip
    installed_plugins
  3. uasi commented on Mar 24, 2022

    @uasi
    Contributor

    Found an unrelated bug in parser.rs, that makes let x = $"=" work by accident.

    if (bytes.starts_with(b"\'") || (bytes.starts_with(b"$\""))) && !bytes.ends_with(b"\'") {

    That b"$\"" should be b"$\'". By fixing it, both let x = $'=' and let x = $"=" (EDIT: and let x = '=' and let x = "=") raise wrong parse error.

  4. added this to the v0.61.0 milestone on Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions