Repository navigation
split: don't read an option's value in combined shorts as obsolete lines - #15641
ozenyunus35 wants to merge 3 commits into
Conversation
| if option_value_reached { | ||
| return true; | ||
| } | ||
| if matches!(c, 'a' | 'b' | 'C' | 'l' | 'n' | 't') { |
There was a problem hiding this comment.
this list of letters is now in 3 places (see should_extract_obs_lines and handle_preceding_options), could it be a shared const?
There was a problem hiding this comment.
@sylvestre Done, it's now a shared SHORT_OPTS_WITH_VALUE const used in all three places.
|
Binary size comparison: |
| // even if it starts with '-' (which would be treated as hyphen prefixed value) | ||
| *preceding_short_opt_req_value = matches!(slice, "-b" | "-C" | "-l" | "-n" | "-a" | "-t"); | ||
| *preceding_short_opt_req_value = | ||
| matches!(slice.as_bytes(), [b'-', c] if SHORT_OPTS_WITH_VALUE.contains(c)); |
There was a problem hiding this comment.
this only catches -l alone, so -dl -5 still reads -5 as obsolete lines
could it also match a group ending with one of these letters? fine in a follow-up too
There was a problem hiding this comment.
@sylvestre Done in c5fa058: a value option that ends a short option group (-dl -5) now takes the next argument like a lone one. Only the first value option in the group counts, so -a2l -5 still reads 2l as the suffix length, as GNU does. Added a test.
In '-dn10' the '10' is the value of -n, but the obsolete '-N' lines option was extracted from it, so split failed with 'cannot split in more than one way'. Stop looking for obsolete lines digits after an option that takes a value (-a, -b, -C, -l, -n, -t).
c5fa058 to
866c17c
Compare
splitaccepts the obsolete-Noption (lines per file) inside a group of short options, as in-x200de.handle_extract_obs_linestook every run of digits in such a group as that value. That included digits that belong to an option in the same group which takes a value. Sosplit -dn10 fileread-d -n -10, and failed:The rest of a group after
-a,-b,-C,-l,-nor-tis that option's value, so the extraction now stops there. These are the same lettersshould_extract_obs_linesalready checks for at the start of a group.-x200a4and-d200a4still read200as the lines value, as before.I added
test_split_option_value_within_combined_shortsfor-dn10and-xl25. It fails without the change, and alltest_splittests and theuu_splitunit tests pass.I also compared 32 option sets with GNU 9.12 on
seq 20, checking the output files, stderr and the exit code. They include values in the same argument and in the next one (-dn10,-dn 10,-dnr/3,-dC10,-db10,-dt, -l1,-da3 -n2,-da0n3,-del2), plain obsolete values (-2,-d2,-2d,-x200a4,-12 -d), and both together (-dn10 -2,-l2 -3). Onmain, 15 of them differ. With this change, all 32 match.I used an AI assistant to help draft parts of the code and tests; I reviewed the changes and ran the tests myself.