Skip to content

split: don't read an option's value in combined shorts as obsolete lines - #15641

Open
ozenyunus35 wants to merge 3 commits into
uutils:mainfrom
ozenyunus35:split-cluster-option-value
Open

ozenyunus35 wants to merge 3 commits into
uutils:mainfrom
ozenyunus35:split-cluster-option-value

Conversation

@ozenyunus35

Copy link
Copy Markdown
Contributor

split accepts the obsolete -N option (lines per file) inside a group of short options, as in -x200de. handle_extract_obs_lines took 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. So split -dn10 file read -d -n -10, and failed:

seq 20 > in
split -dn10 in
# before: split: cannot split in more than one way    (exit 1)
# after:  x00 ... x09                                  (same as GNU 9.12)

split -xl5 in
# before: split: cannot split in more than one way    (exit 1)
# after:  x00 ... x03                                  (same as GNU 9.12)

The rest of a group after -a, -b, -C, -l, -n or -t is that option's value, so the extraction now stops there. These are the same letters should_extract_obs_lines already checks for at the start of a group. -x200a4 and -d200a4 still read 200 as the lines value, as before.

I added test_split_option_value_within_combined_shorts for -dn10 and -xl25. It fails without the change, and all test_split tests and the uu_split unit 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). On main, 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.

Comment thread src/uu/split/src/split.rs Outdated
if option_value_reached {
return true;
}
if matches!(c, 'a' | 'b' | 'C' | 'l' | 'n' | 't') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this list of letters is now in 3 places (see should_extract_obs_lines and handle_preceding_options), could it be a shared const?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sylvestre Done, it's now a shared SHORT_OPTS_WITH_VALUE const used in all three places.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.04 MB (-304 KB, -0.19%)

Significant per-binary changes:
  date     2.61 MB ->    2.30 MB  (-316 KB, -11.81%)

Comment thread src/uu/split/src/split.rs Outdated
// 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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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).
@sylvestre
sylvestre force-pushed the split-cluster-option-value branch from c5fa058 to 866c17c Compare October 25, 2026 12:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants