aboutsummaryrefslogtreecommitdiff
path: root/editors/vi.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-04-28 09:09:33 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-04-28 17:16:46 +0200
commit4b49422a08b89bd01023e7b4fa73ab058ee66932 (patch)
treefd1d428164b22ab22b2f03cf2307cef9fbd15931 /editors/vi.c
parent93f0b39a0712f3247349f1590757484ca18e725e (diff)
downloadbusybox-w32-4b49422a08b89bd01023e7b4fa73ab058ee66932.tar.gz
busybox-w32-4b49422a08b89bd01023e7b4fa73ab058ee66932.tar.bz2
busybox-w32-4b49422a08b89bd01023e7b4fa73ab058ee66932.zip
vi: fix changes to word at end of line. Closes 11796
As reported in bug 11796 BusyBox vi incorrectly handles changes to a word at the end of a line. If the following line starts with whitespace changing or deleting the last word of a line with the 'cw' or 'dw' commands causes the lines to be joined. This happens because the range for the change returned by find_range() covers all whitespace after the word, including newlines. The problem can be fixed by setting 'ml' to zero to indicate to yank_delete() that processing should stop at the end of the current line. However, this results in a new problem. 'dw' correctly deletes all whitespace following the word but so does 'cw', which should preserve the trailing whitespace. To fix this the code to omit whitespace from the change is modified to include all whitespace not just blanks. function old new delta do_cmd 5034 5069 +35 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 35/0) Total: 35 bytes Reported-by: David Kelly <david.kelly@liberica.ch> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--editors/vi.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/editors/vi.c b/editors/vi.c
index c4360f8d3..dfef42019 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3770,11 +3770,10 @@ static void do_cmd(int c)
3770 if (c1 == 27) { // ESC- user changed mind and wants out 3770 if (c1 == 27) { // ESC- user changed mind and wants out
3771 c = c1 = 27; // Escape- do nothing 3771 c = c1 = 27; // Escape- do nothing
3772 } else if (strchr("wW", c1)) { 3772 } else if (strchr("wW", c1)) {
3773 ml = 0; // multi-line ranges aren't allowed for words
3773 if (c == 'c') { 3774 if (c == 'c') {
3774 // don't include trailing WS as part of word 3775 // don't include trailing WS as part of word
3775 while (isblank(*q)) { 3776 while (isspace(*q) && q > p) {
3776 if (q <= text || q[-1] == '\n')
3777 break;
3778 q--; 3777 q--;
3779 } 3778 }
3780 } 3779 }