Commit b23649e
committed
Fix field separator for $* in here-document
Reproducer:
IFS=/
set a b c
cat <<EOF
$*
EOF
Actual output: a b c
Expected output: a/b/c
In any context in which field splitting is not possible, POSIX
specifies that $* uses the first character of $IFS as the output
field separator.[*] Here-documents are such a context.
Analysis: In macro.c, there are three places where IFS is
initialised - in sh_mactrim, sh_macexpand and in sh_machere. The
latter function deals with here-documents. IFS is initialised by
pointing ifsp to the value of IFSNOD and setting ifs to the first
byte of this value. However, in sh_machere, ifs is hardcoded to a
space. This is the bug.
src/cmd/ksh93/sh/macro.c:
- Add setup_ifs function to centralise this logic.
- Call setup_ifs in the three places mentioned, replacing the
duplicative old code (including the buggy version).
[*] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_05_021 parent 409a886 commit b23649e
3 files changed
+43
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
148 | 161 | | |
149 | 162 | | |
150 | 163 | | |
| |||
167 | 180 | | |
168 | 181 | | |
169 | 182 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 183 | + | |
174 | 184 | | |
175 | 185 | | |
176 | 186 | | |
| |||
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 217 | + | |
211 | 218 | | |
212 | 219 | | |
213 | 220 | | |
| |||
275 | 282 | | |
276 | 283 | | |
277 | 284 | | |
278 | | - | |
279 | | - | |
| 285 | + | |
280 | 286 | | |
281 | 287 | | |
282 | 288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
583 | 604 | | |
584 | 605 | | |
0 commit comments