summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2022-07-29 22:39:53 +0100
committerDavid Mitchell <davem@iabyn.com>2022-07-29 23:00:28 +0100
commit5d7d8ffc298134400c054265830d47abb6ee7845 (patch)
tree6ca894a8cb329554d3a58707423e97085da982df /toke.c
parent68f7e83eef77f17571800a31dc20f6df48e72e9a (diff)
downloadperl-5d7d8ffc298134400c054265830d47abb6ee7845.tar.gz
formats: fix splitting on non-spaces
GH #19985 formats have a mode where they can repeatedly split a string to fill within a fixed text width, splitting on (by default), spaces, newlines and hyphens. The splitting code was heavily rewritten by me in v5.19.5-218-g9b4bdfd44e, but in that patch I introduced a couple of off-by-one errors when splitting on non-white-space characters (i.e. the hyphen by default). It turns out that splitting on a hyphen is completely untested in core, and further, no one noticed the problems in the wild until this ticket, 8 years later! The first issue, and the one in the bug report, is that when splitting, the calculation for how many spaces to pad to the end of the field was off by one, so: $v1 = "AB-CDE"; format STDOUT = [^<<<]~~ $v1 . write; gives: [AB- ] [CDE ] but should have given: [AB- ] [CDE ] The second issue was that it was detecting a hyphen one character further along than the maximum field length and still splitting it there: as above, but $v1 = "ABCD-E"; gives: [ABCD-] [E ] but should have given: [ABCD] [-E ] The latter was because the non-space split code was using the same logic as the split-on-space code, which is allowed to split on a space which is one character beyond the maximum length. This commit fixes both issues, and adds some tests.
Diffstat (limited to 'toke.c')
0 files changed, 0 insertions, 0 deletions