From 800f2414fb886dccc87cbf300b80b5a46212637c Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 18 Jan 2024 10:22:12 +0100 Subject: [PATCH] Fix regression in split_string_tok() If there's no more separator we break early but dont update pos, so we go into the code path that asserts we have reached the limit. --- src/wcstringutil.rs | 11 +++++++---- tests/checks/read.fish | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wcstringutil.rs b/src/wcstringutil.rs index 14e8489e8..4f0e8ad21 100644 --- a/src/wcstringutil.rs +++ b/src/wcstringutil.rs @@ -349,10 +349,13 @@ pub fn split_string_tok<'val>( let max_results = max_results.unwrap_or(usize::MAX); while pos < end && out.len() + 1 < max_results { // Skip leading seps. - pos += match val[pos..].iter().position(|c| !seps.contains(*c)) { - Some(p) => p, - None => break, - }; + match val[pos..].iter().position(|c| !seps.contains(*c)) { + Some(p) => pos += p, + None => { + pos = end; + break; + } + } // Find next sep. let next_sep = val[pos..] diff --git a/tests/checks/read.fish b/tests/checks/read.fish index 1172a6e70..38528d590 100644 --- a/tests/checks/read.fish +++ b/tests/checks/read.fish @@ -389,3 +389,7 @@ echo foo | read status # CHECKERR: (Type 'help read' for related documentation) echo read $status # CHECK: read 2 + +echo ' foo' | read -n 1 -la var +set -S var +#CHECK: $var: set in local scope, unexported, with 0 elements