0
0
mirror of https://github.com/vim/vim.git synced 2025-10-18 07:54:29 -04:00

patch 9.1.1027: no sanitize check when running linematch

Problem:  no sanitize check when running linematch
Solution: add sanitize check before applying the linematch algorithm,
          similar to diff_find_change() (Jonathon)

closes: #16446

Signed-off-by: Jonathon <jonathonwhite@protonmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Jonathon
2025-01-17 13:37:35 +01:00
committed by Christian Brabandt
parent 3a738fccaa
commit ca307efe48
4 changed files with 62 additions and 10 deletions

View File

@@ -1265,7 +1265,7 @@ func CloseoffSetup()
call setline(1, ['one', 'tow', 'three'])
diffthis
call assert_equal(1, &diff)
only!
bw!
endfunc
func Test_diff_closeoff()
@@ -2529,7 +2529,8 @@ func Test_diffget_diffput_linematch()
" put from window 2 using dp line 17
call term_sendkeys(buf, "2\<c-w>w")
call term_sendkeys(buf, "17gg")
call term_sendkeys(buf, "17gg")
call term_sendkeys(buf, ":diffput\<CR>")
call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_19', {})
" clean up
call StopVimInTerminal(buf)
@@ -2549,7 +2550,8 @@ func Test_linematch_diff()
\ '// d?',
\ '// d?' ],
\ ['!',
\ 'abc d!',
\ 'abc d!',
\ 'd!'])
call VerifyScreenDump(buf, 'Test_linematch_diff1', {})
" clean up
call StopVimInTerminal(buf)
@@ -2575,7 +2577,8 @@ func Test_linematch_diff_iwhite()
\ ' // for (int j = 0; j < 10; i++) {',
\ ' // }',
\ '}'])
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {})
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {})
call term_sendkeys(buf, ":set diffopt+=iwhiteall\<CR>")
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite2', {})
" clean up
call StopVimInTerminal(buf)
@@ -2612,7 +2615,8 @@ func Test_linematch_diff_grouping()
\ '?C',
\ '?A',
\ '?B',
\ '?C',
\ '?C',
\ '?C'])
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {})
" clean up
call StopVimInTerminal(buf)
@@ -2643,11 +2647,10 @@ func Test_linematch_diff_scroll()
" both windows
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll0', {})
call term_sendkeys(buf, "3\<c-e>")
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {})
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {})
call term_sendkeys(buf, "3\<c-e>")
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll2', {})
" clean up
endfunc
call StopVimInTerminal(buf)
endfunc
@@ -2694,7 +2697,8 @@ func Test_linematch_line_limit_exceeded()
\ 'something'])
call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded1', {})
" after increasing the count to 30, the limit is not exceeded, and the
" alignment algorithm will run on the largest diff block here
" alignment algorithm will run on the largest diff block here
call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded2', {})
" clean up
call StopVimInTerminal(buf)
@@ -2731,6 +2735,31 @@ func Test_linematch_3diffs()
\ ["",
\ " common line",
\ " BBB",
\ " BBB",
\ " BBB"])
call VerifyScreenDump(buf, 'Test_linematch_3diffs1', {})
" clean up
call StopVimInTerminal(buf)
endfunc
" this used to access invalid memory
func Test_linematch_3diffs_sanity_check()
CheckScreendump
call delete('.Xfile_linematch1.swp')
call delete('.Xfile_linematch2.swp')
call delete('.Xfile_linematch3.swp')
let lines =<< trim END
set diffopt+=linematch:60
call feedkeys("Aq\<esc>")
call feedkeys("GAklm\<esc>")
call feedkeys("o")
END
call writefile(lines, 'Xlinematch_3diffs.vim', 'D')
call writefile(['abcd', 'def', 'hij'], 'Xfile_linematch1', 'D')
call writefile(['defq', 'hijk', 'nopq'], 'Xfile_linematch2', 'D')
call writefile(['hijklm', 'nopqr', 'stuv'], 'Xfile_linematch3', 'D')
call WriteDiffFiles3(0, [], [], [])
let buf = RunVimInTerminal('-d -S Xlinematch_3diffs.vim Xfile_linematch1 Xfile_linematch2 Xfile_linematch3', {})
call VerifyScreenDump(buf, 'Test_linematch_3diffs2', {})
" clean up