Commit 3e15738
committed
cut: fix -s flag ignored when delimiter is newline
When using newline as the delimiter (-d $'\n') with -s (only-delimited),
cut should suppress lines that do not contain the delimiter. However,
cut_fields_newline_char_delim() was not checking the only_delimited flag,
causing it to always output even when -s was specified.
The fix uses read_until() instead of split() to read segments. Unlike
split(), read_until() includes the delimiter in the buffer when found,
allowing us to detect whether a delimiter was actually present or if
we just hit EOF.
This commit:
- Adds only_delimited parameter to cut_fields_newline_char_delim()
- Uses read_until() to detect delimiter presence while reading
- If no delimiter found and only_delimited is true, returns early
- Adds test case for newline delimiter with -s flag
Fixes #100121 parent 81ee8d1 commit 3e15738
2 files changed
+51
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
| 268 | + | |
268 | 269 | | |
269 | 270 | | |
270 | 271 | | |
271 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
272 | 295 | | |
273 | | - | |
274 | 296 | | |
275 | 297 | | |
276 | 298 | | |
| |||
303 | 325 | | |
304 | 326 | | |
305 | 327 | | |
306 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
307 | 336 | | |
308 | 337 | | |
309 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
304 | 323 | | |
305 | 324 | | |
306 | 325 | | |
| |||
0 commit comments