fix(shada): don't store empty replacement string

This commit is contained in:
Andre Toerien
2025-04-19 14:55:39 +02:00
parent a6591950f6
commit 1f503ac7c0
2 changed files with 32 additions and 18 deletions

View File

@@ -2417,6 +2417,7 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
// Initialize substitute replacement string // Initialize substitute replacement string
SubReplacementString sub; SubReplacementString sub;
sub_get_replacement(&sub); sub_get_replacement(&sub);
if (sub.sub != NULL) { // Don't store empty replacement string
wms->replacement = (PossiblyFreedShadaEntry) { wms->replacement = (PossiblyFreedShadaEntry) {
.can_free_entry = false, .can_free_entry = false,
.data = { .data = {
@@ -2431,6 +2432,7 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
} }
}; };
} }
}
// Initialize global marks // Initialize global marks
if (dump_global_marks) { if (dump_global_marks) {

View File

@@ -239,9 +239,10 @@ describe('ShaDa support code', function()
nvim_command('silent! /«/') nvim_command('silent! /«/')
expect_exit(nvim_command, 'qall!') expect_exit(nvim_command, 'qall!')
reset() reset()
fn.setline('.', { '\171«' }) fn.setline('.', { 'foo', '\171«' })
nvim_command('~&') nvim_feed('gg0n')
eq('\171', fn.getline('.')) eq({ 0, 2, 2, 0 }, fn.getpos('.'))
eq('\171«', fn.getline('.'))
eq('', fn.histget('/', -1)) eq('', fn.histget('/', -1))
end) end)
@@ -250,9 +251,10 @@ describe('ShaDa support code', function()
nvim_command('silent! /\171/') nvim_command('silent! /\171/')
expect_exit(nvim_command, 'qall!') expect_exit(nvim_command, 'qall!')
reset() reset()
fn.setline('.', { '\171«' }) fn.setline('.', { 'foo', '\171«' })
nvim_command('~&') nvim_feed('gg0n')
eq('«', fn.getline('.')) eq({ 0, 2, 1, 0 }, fn.getpos('.'))
eq('\171«', fn.getline('.'))
eq('', fn.histget('/', -1)) eq('', fn.histget('/', -1))
end) end)
@@ -277,4 +279,14 @@ describe('ShaDa support code', function()
nvim_command('wshada') nvim_command('wshada')
assert_alive() assert_alive()
end) end)
it('does not dump empty replacement string', function()
expect_exit(nvim_command, 'qall!')
reset()
fn.setline('.', { 'foo', 'bar' })
nvim_command('language C')
nvim_feed('/f\n')
local err = pcall_err(nvim_command, '~&')
eq('Vim(~):E33: No previous substitute regular expression', err)
end)
end) end)