aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2018-06-13 18:21:25 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2018-06-14 14:00:09 +0200
commit5442f0b6221946e482dec2cb82576f0ba38900fe (patch)
tree8a977ba24079aabb5a6babacd314f20d95c40cf5
parenta7bb63c55dacfa822e1a24d041771d9e8d83a980 (diff)
downloadrneovim-5442f0b6221946e482dec2cb82576f0ba38900fe.tar.gz
rneovim-5442f0b6221946e482dec2cb82576f0ba38900fe.tar.bz2
rneovim-5442f0b6221946e482dec2cb82576f0ba38900fe.zip
fillchars: make checks more strict and improve tests
-rw-r--r--runtime/doc/vim_diff.txt3
-rw-r--r--src/nvim/option.c12
-rw-r--r--test/functional/options/fillchars_spec.lua33
3 files changed, 37 insertions, 11 deletions
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 9dd03079fe..5394414947 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -180,7 +180,8 @@ Options:
'cpoptions' flags: |cpo-_|
'display' flag `msgsep` to minimize scrolling when showing messages
'guicursor' works in the terminal
- 'fillchars' flag `msgsep` (see 'display' above)
+ 'fillchars' flags: `msgsep` (see 'display' above)
+ and `eob` for |EndOfBuffer| marker
'inccommand' shows interactive results for |:substitute|-like commands
'scrollback'
'statusline' supports unlimited alignment sections
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 3c1a70e90d..e65798e57a 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -3438,16 +3438,20 @@ static char_u *set_chars_option(char_u **varp)
&& p[len] == ':'
&& p[len + 1] != NUL) {
s = p + len + 1;
- c1 = mb_ptr2char_adv((const char_u **)&s);
- if (mb_char2cells(c1) > 1) {
+
+ // TODO(bfredl): use schar_T representation and utfc_ptr2len
+ int c1len = utf_ptr2len(s);
+ c1 = mb_cptr2char_adv((const char_u **)&s);
+ if (mb_char2cells(c1) > 1 || (c1len == 1 && c1 > 127)) {
continue;
}
if (tab[i].cp == &lcs_tab2) {
if (*s == NUL) {
continue;
}
- c2 = mb_ptr2char_adv((const char_u **)&s);
- if (mb_char2cells(c2) > 1) {
+ int c2len = utf_ptr2len(s);
+ c2 = mb_cptr2char_adv((const char_u **)&s);
+ if (mb_char2cells(c2) > 1 || (c2len == 1 && c2 > 127)) {
continue;
}
}
diff --git a/test/functional/options/fillchars_spec.lua b/test/functional/options/fillchars_spec.lua
index 4ac3655f08..ab61935d4c 100644
--- a/test/functional/options/fillchars_spec.lua
+++ b/test/functional/options/fillchars_spec.lua
@@ -1,6 +1,9 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
-local clear, execute = helpers.clear, helpers.execute
+local clear, command = helpers.clear, helpers.command
+local eval = helpers.eval
+local eq = helpers.eq
+local exc_exec = helpers.exc_exec
describe("'fillchars'", function()
local screen
@@ -15,8 +18,15 @@ describe("'fillchars'", function()
screen:detach()
end)
+ local function shouldfail(val,errval)
+ errval = errval or val
+ eq('Vim(set):E474: Invalid argument: fillchars='..errval,
+ exc_exec('set fillchars='..val))
+ end
+
describe('"eob" flag', function()
- it('renders empty lines at the end of the buffer with eob', function()
+ it("uses '~' by default", function()
+ eq('', eval('&fillchars'))
screen:expect([[
^ |
~ |
@@ -24,22 +34,33 @@ describe("'fillchars'", function()
~ |
|
]])
- execute('set fillchars+=eob:\\ ')
+ end)
+ it('supports whitespace', function()
+ command('set fillchars=eob:\\ ')
screen:expect([[
^ |
|
|
|
- :set fillchars+=eob:\ |
+ |
]])
- execute('set fillchars+=eob:ñ')
+ end)
+ it('supports multibyte char', function()
+ command('set fillchars=eob:ñ')
screen:expect([[
^ |
ñ |
ñ |
ñ |
- :set fillchars+=eob:ñ |
+ |
]])
end)
+ it('handles invalid values', function()
+ shouldfail('eob:') -- empty string
+ shouldfail('eob:馬') -- doublewidth char
+ shouldfail('eob:å̲') -- composing chars
+ shouldfail('eob:xy') -- two ascii chars
+ shouldfail('eob:\255', 'eob:<ff>') -- invalid UTF-8
+ end)
end)
end)