Skip to content

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

Closed

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

Activity

  1. added
    category:inconsistent-behavior
    on Jan 15, 2023
  2. MehulG commented on Jan 16, 2023

    @MehulG
    Contributor

    Hey, could you assign me this issue? If I understood it correctly, the inconsistency should be resolved by having something like this:

    〉"abcdefg" | str substring 1..3
    bcd
    
  3. webbedspace commented on Jan 16, 2023

    @webbedspace
    Contributor

    While you're at it, could you make str substring 1..<3 only produce bc like one would expect? Currently it's treated the same as 1..3.

  4. MehulG commented on Jan 16, 2023

    @MehulG
    Contributor

    yes, definitely

  5. rgwood commented on Mar 1, 2023

    @rgwood
    ContributorAuthor

    @MehulG Let us know if you're still interested in this one.

  6. fdncred commented on May 30, 2023

    @fdncred
    Contributor

    @MehulG Were you going to work in this?

  7. added this to the v0.94.0 milestone on May 23, 2024
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:inconsistent-behavior

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions