mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 05:16:05 +01:00
40032: consistency in handling of subscript slices outside the bounds of an array parameter
unposted: README: example describing 40032
This commit is contained in:
parent
596ba302e6
commit
a9fe87e18c
3 changed files with 55 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
|||
2016-11-29 Barton E. Schaefer <schaefer@brasslantern.com>
|
||||
|
||||
* unposted: README: example describing 40032
|
||||
|
||||
* 40032: Src/params.c: consistency in handling of subscript
|
||||
slices outside the bounds of an array parameter
|
||||
|
||||
2016-11-29 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 40037: Joshua Rubin: Unicode 9 character width support.
|
||||
|
|
39
README
39
README
|
@ -121,6 +121,45 @@ Previously, only "typeset" commands were output, never using "-g".
|
|||
<Tab> would be accepted to mean [Y]. Now <Space> and <Tab> are invalid
|
||||
choices: typing either of them remains at the prompt.
|
||||
|
||||
9) The $ary[i,j] subscript syntax to take a slice of an array behaves
|
||||
differently when both i and j are larger than the number of elements in
|
||||
the array. When i == j, such a slice always yields an empty array, and
|
||||
when i < j it always yields an array of one empty string element. The
|
||||
following example illustrates how this differs from past versions.
|
||||
|
||||
nargs() { print $# }
|
||||
a=(one two)
|
||||
for i in 1 2 3 4; do
|
||||
for j in 1 2 3 4 5; do
|
||||
print -n "$i $j => "
|
||||
nargs "${(@)a[i,j]}"
|
||||
done
|
||||
done
|
||||
|
||||
5.2 | 5.3 **
|
||||
----------+----------
|
||||
1 1 => 1 | 1 1 => 1
|
||||
1 2 => 2 | 1 2 => 2
|
||||
1 3 => 2 | 1 3 => 2
|
||||
1 4 => 2 | 1 4 => 2
|
||||
1 5 => 2 | 1 5 => 2
|
||||
2 1 => 0 | 2 1 => 0
|
||||
2 2 => 1 | 2 2 => 1
|
||||
2 3 => 1 | 2 3 => 1
|
||||
2 4 => 1 | 2 4 => 1
|
||||
2 5 => 1 | 2 5 => 1
|
||||
3 1 => 0 | 3 1 => 0
|
||||
3 2 => 0 | 3 2 => 0
|
||||
3 3 => 0 | 3 3 => 0
|
||||
3 4 => 0 | 3 4 => 1 **
|
||||
3 5 => 0 | 3 5 => 1 **
|
||||
4 1 => 0 | 4 1 => 0
|
||||
4 2 => 0 | 4 2 => 0
|
||||
4 3 => 0 | 4 3 => 0
|
||||
4 4 => 1 | 4 4 => 0 **
|
||||
4 5 => 1 | 4 5 => 1
|
||||
|
||||
|
||||
Incompatibilities between 5.0.8 and 5.2
|
||||
---------------------------------------
|
||||
|
||||
|
|
11
Src/params.c
11
Src/params.c
|
@ -2299,9 +2299,16 @@ getarrvalue(Value v)
|
|||
if (v->end <= v->start) {
|
||||
s = arrdup_max(nular, 0);
|
||||
}
|
||||
else if (arrlen_lt(s, v->start) || v->start < 0) {
|
||||
else if (v->start < 0) {
|
||||
s = arrdup_max(nular, 1);
|
||||
} else {
|
||||
}
|
||||
else if (arrlen_le(s, v->start)) {
|
||||
/* Handle $ary[i,i] consistently for any $i > $#ary
|
||||
* and $ary[i,j] consistently for any $j > $i > $#ary
|
||||
*/
|
||||
s = arrdup_max(nular, v->end - (v->start + 1));
|
||||
}
|
||||
else {
|
||||
/* Copy to a point before the end of the source array:
|
||||
* arrdup_max will copy at most v->end - v->start elements,
|
||||
* starting from v->start element. Original code said:
|
||||
|
|
Loading…
Reference in a new issue