robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Chris Hebertfix(terminal): OSC 52 multiline copy replaces newlines with NUL #41097e58f29ca3e

master
2.3 KiB87 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local eq = t.eq
6local retry = t.retry
7
8local clear = n.clear
9local fn = n.fn
10local testprg = n.testprg
11local exec_lua = n.exec_lua
12local eval = n.eval
13
14describe(':terminal', function()
15  before_each(function()
16    clear()
17
18    exec_lua([[
19      local function clipboard(reg, type)
20        if type == 'copy' then
21          return function(lines)
22            vim.g.clipboard_lines = lines
23            local data = table.concat(lines, '\n')
24            vim.g.clipboard_data = data
25          end
26        end
27
28        if type == 'paste' then
29          return function()
30            error()
31          end
32        end
33
34        error('invalid type: ' .. type)
35      end
36
37      vim.g.clipboard = {
38        name = 'Test',
39        copy = {
40          ['+'] = clipboard('+', 'copy'),
41          ['*'] = clipboard('*', 'copy'),
42        },
43        paste = {
44          ['+'] = clipboard('+', 'paste'),
45          ['*'] = clipboard('*', 'paste'),
46        },
47      }
48    ]])
49  end)
50
51  local function osc52(arg)
52    return string.format('\027]52;;%s\027\\', arg)
53  end
54
55  it('can write to the system clipboard', function()
56    eq('Test', eval('g:clipboard.name'))
57
58    local text = 'Hello, world! This is some\nexample text\nthat spans multiple\nlines'
59    local encoded = exec_lua('return vim.base64.encode(...)', text)
60
61    fn.jobstart({ testprg('shell-test'), '-t', osc52(encoded) }, { term = true })
62
63    retry(nil, 1000, function()
64      eq(text, exec_lua([[ return vim.g.clipboard_data ]]))
65    end)
66
67    -- Multiline payloads must arrive split into separate list items: a newline
68    -- inside a single item would be sent to a command-line provider as NUL.
69    eq({
70      'Hello, world! This is some',
71      'example text',
72      'that spans multiple',
73      'lines',
74    }, exec_lua([[ return vim.g.clipboard_lines ]]))
75  end)
76
77  it('multiline copy does not send newlines as NUL #41097', function()
78    local text = '\nfoo\n\nbar\n'
79    local encoded = exec_lua('return vim.base64.encode(...)', text)
80
81    fn.jobstart({ testprg('shell-test'), '-t', osc52(encoded) }, { term = true })
82
83    retry(nil, 1000, function()
84      eq({ '', 'foo', '', 'bar', '' }, exec_lua([[ return vim.g.clipboard_lines ]]))
85    end)
86  end)
87end)