Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: word[-1]= breaks on multibyte?
- X-seq: zsh-workers 28340
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: word[-1]= breaks on multibyte?
- Date: Sun, 10 Oct 2010 18:20:40 +0100
- In-reply-to: <AANLkTi=Uc-2ykr9p=Ee3RQ6t-D8f9j8Tiwe8qwP5RVgd@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <AANLkTi=Uc-2ykr9p=Ee3RQ6t-D8f9j8Tiwe8qwP5RVgd@xxxxxxxxxxxxxx>
On Fri, 8 Oct 2010 23:20:30 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> % word=abcã
> % word[-1]=
> % echo $word
> abcÂ
The end index is recorded as the last character, not one beyond it. We
need to increment it when we use it. For assignment that's not
done properly.
It looked like there might have been a problem with indexing off the end
even without multibyte characters at that point.
There are no other references to MULTIBYTE_SUPPORT in params.c, so I
wouldn't be surprised if there were other problems like this.
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.162
diff -p -u -r1.162 params.c
--- Src/params.c 31 Aug 2010 19:32:57 -0000 1.162
+++ Src/params.c 10 Oct 2010 17:16:40 -0000
@@ -2275,9 +2275,22 @@ setstrvalue(Value v, char *val)
if (v->start > zlen)
v->start = zlen;
if (v->end < 0) {
- v->end += zlen + 1;
- if (v->end < 0)
+ v->end += zlen;
+ if (v->end < 0) {
v->end = 0;
+ } else if (v->end >= zlen) {
+ v->end = zlen;
+ } else {
+#ifdef MULTIBYTE_SUPPORT
+ if (isset(MULTIBYTE)) {
+ v->end += MB_METACHARLEN(z + v->end);
+ } else {
+ v->end++;
+ }
+#else
+ v->end++;
+#endif
+ }
}
else if (v->end > zlen)
v->end = zlen;
Index: Test/D07multibyte.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D07multibyte.ztst,v
retrieving revision 1.34
diff -p -u -r1.34 D07multibyte.ztst
--- Test/D07multibyte.ztst 24 Jul 2009 18:35:53 -0000 1.34
+++ Test/D07multibyte.ztst 10 Oct 2010 17:16:40 -0000
@@ -447,3 +447,21 @@
print $(( [#16] #REPLY ))
0:read passes through invalid multibyte characters
>0xC5
+
+ word=abcã
+ word[-1]=
+ print $word
+ word=abcã
+ word[-2]=
+ print $word
+ word=abcã
+ word[4]=d
+ print $word
+ word=abcã
+ word[3]=not_c
+ print $word
+0:assignment with negative indices
+>abc
+>abã
+>abcd
+>abnot_cã
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author