Skip to content

Ranges and str substring are inconsistent (off by 1) #7761

@rgwood

Description

@rgwood

Describe the bug

1..3 produces 3 numbers:

〉1..3
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
╰───┴───╯

str substring 1..3 produces 2 characters:

"abcdefg" | str substring 1..3
bc

That's an unpleasant inconsistency.

How to reproduce

Use str substring with a range, observe that it produces 1 fewer character than there are numbers in the range.

Expected behavior

I expect that a range with n numbers should produce a string of n characters when used with str substring.

Screenshots

No response

Configuration

key value
version 0.74.1
branch main
commit_hash b004aac
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.65.0 (897e37553 2022-11-02)
rust_channel 1.65.0-x86_64-pc-windows-msvc
cargo_version cargo 1.65.0 (4bc8f24d3 2022-10-20)
pkg_version 0.74.1
build_time 2023-01-12 12:55:53 -08:00
build_rust_channel release
features database, default, trash, which, zip
installed_plugins

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpected

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions