nushell/crates
Bahex b55ed69c92
fix range bugs in str substring, str index-of, slice, bytes at (#14863)
- fixes #14769

# Description

## Bugs

-   `str substring 0..<0`

When passed a range containing no elements, for non-zero cases `str
substring` behaves correctly:
 
    ```nushell
    ("hello world" | str substring 1..<1) == ""
    # => true
    ```

    but if the range is `0..<0`, it returns the whole string instead

    ```nushell
    "hello world" | str substring 0..<0
    # => hello world
    ```
-   `[0 1 2] | range 0..<0`
    Similar behavior to `str substring`
-   `str index-of`
    - off-by-one on end bounds
    - underflow on negative start bounds
- `bytes at` has inconsistent behavior, works correctly when the size is
known, returns one byte less when it's not known (streaming)
This can be demonstrated by comparing the outputs of following snippets
    ```nushell
    "hello world" | into binary | bytes at ..<5 | decode
    # => hello

"hello world" | into binary | chunks 1 | bytes collect | bytes at ..<5 |
decode
    # => hell
    ```
- `bytes at` panics on decreasing (`5..3`) ranges if the input size is
known. Does not panic with streaming input.

## Changes

- implement `FromValue` for `IntRange`, as it is very common to use
integer ranges as arguments
- `IntRange::absolute_start` can now point one-past-end
- `IntRange::absolute_end` converts relative `Included` bounds to
absolute `Excluded` bounds
- `IntRange::absolute_bounds` is a convenience method that calls the
other `absolute_*` methods and transforms reverse ranges to empty at
`start` (`5..3` => `5..<5`)
- refactored `str substring` tests to allow empty exclusive range tests
- fix the `0..<0` case for `str substring` and `str index-of`
- `IntRange::distance` never returns `Included(0)`

  As a general rule `Included(n) == Excluded(n + 1)`.
  
This makes returning `Included(0)` bug prone as users of the function
will likely rely on this general rule and cause bugs.
- `ByteStream::slice` no longer has an off-by-one on inputs without a
known size. This affected `bytes at`.
- `bytes at` no longer panics on reverse ranges
- `bytes at` is now consistent between streaming and non streaming
inputs.

# User-Facing Changes
There should be no noticeable changes other than the bugfix.

# Tests + Formatting

- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib

# After Submitting
N/A
2025-01-30 06:50:01 -06:00
..
nu_plugin_custom_values Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu_plugin_example Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu_plugin_formats Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu_plugin_gstat Bump git2 from 0.19.0 to 0.20.0 (#14776) 2025-01-08 13:53:02 +00:00
nu_plugin_inc Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu_plugin_nu_example Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu_plugin_polars Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
nu_plugin_python Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu_plugin_query Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu_plugin_stress_internals Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-cli fix(cli): completion in nested blocks (#14856) 2025-01-30 01:15:38 -05:00
nu-cmd-base Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-cmd-extra Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
nu-cmd-lang Bump shadow-rs from 0.37.0 to 0.38.0 (#14952) 2025-01-29 08:56:27 +08:00
nu-cmd-plugin Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
nu-color-config Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-command fix range bugs in str substring, str index-of, slice, bytes at (#14863) 2025-01-30 06:50:01 -06:00
nu-derive-value Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-engine Immediately return error if detected as pipeline input or positional argument (#14874) 2025-01-30 06:47:22 -06:00
nu-explore Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
nu-glob Create nu_glob::is_glob function (#14717) 2025-01-01 19:04:17 -05:00
nu-json Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-lsp fix(completion): DotNuCompletion now completes nu scripts in const $NU_LIB_DIRS (#14955) 2025-01-29 05:54:12 -06:00
nu-parser fix(parser): mixed side effects of different choices in parse_oneof (#14912) 2025-01-30 06:30:45 -06:00
nu-path Use ref-cast crate to remove some unsafe (#14897) 2025-01-26 12:43:45 -08:00
nu-plugin Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
nu-plugin-core Replaced IoError::new calls that still had Span::unknown() (#14968) 2025-01-30 06:20:26 -06:00
nu-plugin-engine Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
nu-plugin-protocol Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-plugin-test-support Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
nu-pretty-hex Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-protocol fix range bugs in str substring, str index-of, slice, bytes at (#14863) 2025-01-30 06:50:01 -06:00
nu-std Rename std/core to std/prelude (#14962) 2025-01-29 11:16:12 -05:00
nu-system Replace std::time::Instant with web_time::Instant (#14668) 2024-12-25 16:50:02 +08:00
nu-table Fix #14842 (#14885) 2025-01-22 06:49:25 -06:00
nu-term-grid Bump version to 0.101.1 (#14661) 2024-12-24 23:47:00 +01:00
nu-test-support Improve and fix filesize formatting/display (#14397) 2025-01-22 22:24:51 -08:00
nu-utils Improve and fix filesize formatting/display (#14397) 2025-01-22 22:24:51 -08:00
nuon fix nuon conversions of range values (#14687) 2025-01-07 21:29:39 +01:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.