nushell / nushell/nushell

range cannot start with a negative number

Open
#9,177 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A:error-unhelpful A:parser semantics status:needs-core-team-attention status:needs-design
Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 19h
Merged PRs (30d)
85

Description

Describe the bug

Start with a negative number, it will first parse -1 into flag` surround it with quotes, it will be parsed as a string.

How to reproduce
'abc' | str substring -1..                                                                                                                   
Error: nu::parser::unknown_flag

  × The `str substring` command doesn't have flag `-1`.
   ╭─[entry #18:1:1]
 1 │ 'abc' | str substring -1..
   ·                        ┬
   ·                        ╰── unknown flag
   ╰────
  help: Available flags: --help(-h), --grapheme-clusters(-g), --utf-8-bytes(-b). Use `--help` for more information.
Expected behavior

'abc' | str substring -1.. should get c

Screenshots

No response

Configuration
key value
version 0.79.0
branch
commit_hash a1b72611215dbfca257351003204a80c83859e05
build_os linux-x86_64
build_target x86_64-unknown-linux-musl
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
build_time 2023-04-25 20:27:44 +00:00
build_rust_channel release
features default, zip
installed_plugins custom-value generate, custom-value generate2, custom-value update, from eml, from ics, from ini, from vcf, gstat, inc, query, query json, query web, query xml
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with 'abc' | str substring -1.. and trace how the str substring command arguments are parsed, especially the leading negative range value. Add coverage for the expected command and verify that it returns c without treating -1 as a flag.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, shell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.