Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATHC] Fix handling of reversed slices in assignstrvalue
- X-seq: zsh-workers 54397
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATHC] Fix handling of reversed slices in assignstrvalue
- Date: Mon, 27 Apr 2026 06:19:44 +0200
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+NKoQ3JFBJPXpWmPg1GWnFp2mYsHZ+xG5VtD62P6bsc=; fh=RngAOd9wlRc8Glv1v2GOfDUnq2FsyrczungEY8JNfXY=; b=irvFTWgJpXOZd0PcuPQ7r+srxpMJoOxBKpkO+i307BxYORWJYZjdBvVp7VHj7WJo6i qQoA71SwlKf9j0fWi0c+Ygm89TY/8UL/oUpl0P3P5xy/fPE25TiXsoIkJEfRUSc4DQuz BBy67upjKnUZ2bP/eikk0VdpgKqbiRW0cjNzweSk8i2INbqQNwi86CNMshIEFYaDlj3j aFYlD6VP5T0pVduOdRiP01LySDkkDI6J9m1KdRjqvuHEGqk0+3ZneO1HkjMMLtV2nQ10 z0IaQsqX3taX8PtZavt4kzv8sytWItsfG8h97NTWxyobUbQSyHaIMvXaEBj0X/Gaqtxh DC4Q==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1777263599; cv=none; d=google.com; s=arc-20240605; b=LBd89779LQHynDWJcdw+K8kxQgvJuQjAQ8eyZfHXDS+okU6XQ8pk3wQsFIFYiYnKPd KQ3WJqKwC0tcoQJ6DDcr85J3kkHHwLzSemwG4h6REzMBTFYwA15RZCsDEpx0IusKrBn7 urRcs5ncarkzdblw4eEOfFFkaL2qH6CVtAkS3wJKZO/ozUjrT5gpGBouCM1FNTVNBtG7 xbSVDFHH/h0EAeI44dqXSldiqaW2QtgD8Ob02A5U3/5s/vohpijzmGxwOUQ6dsMY8xbU a4JqZ7+3BNZRomfnVGskEksCyGIEBSQ+dqPT2yTBq6+rwsE+gRhzlNzhrigJfFCTOsmX PUGg==
- Archived-at: <https://zsh.org/workers/54397>
- In-reply-to: <CAGdYchutO0TJwdy5WCqtYB-71GQsQeS8R1nYTfzqf-LMJz3AfA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchutO0TJwdy5WCqtYB-71GQsQeS8R1nYTfzqf-LMJz3AfA@mail.gmail.com>
On Sun, Apr 12, 2026 at 4:33 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> Reversed slices (with end index < start index) are handled correctly in array assignments but not in string assignments:
>
> a=(1 2 3 4 5 6 7 8); a[7,2]=(X Y Z); echo a=$a
> s=12345678 ; s[7,2]=XYZ ; echo s=$s
>
> Actual output:
> a=1 2 3 4 5 6 X Y Z 7 8
> s=123456XYZ345678
>
> Expected output:
> a=1 2 3 4 5 6 X Y Z 7 8
> s=123456XYZ78
As far as I know, this syntax isn't documented, and from testing, it
seems to work fine if you use [7,6] instead of [7,2]. That said, the
patch is pretty small. I did suggest at one point that we document the
'trick' of [1,0] to prepend, but it was shot down.
One thing that stands out when reviewing it is that the second hunk is
adding an "if" between an existing "if" and "else if", which feels a
little weird.
Also, now that I look at it more, I'm confused what the purpose of the
first hunk is? How does allowing the second index to run off the end
of the string help us here?
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author