From 895f712df8afc053b59783189954e665ccd21dab Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Jun 2016 23:39:16 +0300 Subject: option: Do not expand options, obtained from XDG vars It is a wrong thing to do, this makes valid variable values be treated incorrectly: in XDG_DATA_HOME='/home/$foo/.local/share' `$foo` should be treated literally and not expanded to `foo` environment variable value. Also makes option_expand not try to expand too long strings even if these too long strings are default values. Previously it thought that default values should always be expanded. Also does not try to expand NULL should it be the default value just in case. Fixes #4961 --- test/functional/options/defaults_spec.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'test') diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index a36939b0bd..161791ab21 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -76,5 +76,3 @@ describe('startup defaults', function() end) end) end) - - -- cgit From 3878626c056ada19a27fe7f0b0df48a6eea0c9af Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Jun 2016 18:16:54 +0300 Subject: functests: Add tests for XDG defaults --- test/functional/helpers.lua | 38 ++++++- test/functional/options/defaults_spec.lua | 169 +++++++++++++++++++++++++++++- 2 files changed, 202 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 02109d0889..6f43ec817c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -216,17 +216,47 @@ local function merge_args(...) return argv end -local function spawn(argv, merge) - local child_stream = ChildProcessStream.spawn(merge and merge_args(prepend_argv, argv) or argv) +local function spawn(argv, merge, env) + local child_stream = ChildProcessStream.spawn( + merge and merge_args(prepend_argv, argv) or argv, + env) return Session.new(child_stream) end local function clear(...) local args = {unpack(nvim_argv)} - for _, arg in ipairs({...}) do + local new_args + local env = nil + local opts = select(1, ...) + if type(opts) == 'table' then + if opts.env then + local env_tbl = {} + for k, v in pairs(opts.env) do + assert(type(k) == 'string') + assert(type(v) == 'string') + env_tbl[k] = v + end + for _, k in ipairs({ + 'HOME', + 'ASAN_OPTIONS', + 'LD_LIBRARY_PATH', 'PATH', + 'NVIM_LOG_FILE', + }) do + env_tbl[k] = os.getenv(k) + end + env = {} + for k, v in pairs(env_tbl) do + env[#env + 1] = k .. '=' .. v + end + end + new_args = opts.args or {} + else + new_args = {...} + end + for _, arg in ipairs(new_args) do table.insert(args, arg) end - set_session(spawn(args)) + set_session(spawn(args, nil, env)) end local function insert(...) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 161791ab21..cc9944947b 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -1,7 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) + local Screen = require('test.functional.ui.screen') -local eval, eq = helpers.eval, helpers.eq + +local meths = helpers.meths local execute = helpers.execute +local clear = helpers.clear +local eval = helpers.eval +local eq = helpers.eq local function init_session(...) local args = { helpers.nvim_prog, '-i', 'NONE', '--embed', @@ -76,3 +81,165 @@ describe('startup defaults', function() end) end) end) + +describe('XDG-based defaults', function() + -- Need to be in separate describe() block to not run clear() twice. + -- Do not put before_each() here for the same reasons. + describe('with too long XDG variables', function() + before_each(function() + clear({env={ + XDG_CONFIG_HOME=('/x'):rep(4096), + XDG_CONFIG_DIRS=(('/a'):rep(2048) + .. ':' .. ('/b'):rep(2048) + .. (':/c'):rep(512)), + XDG_DATA_HOME=('/X'):rep(4096), + XDG_DATA_DIRS=(('/A'):rep(2048) + .. ':' .. ('/B'):rep(2048) + .. (':/C'):rep(512)), + }}) + end) + + it('are correctly set', function() + eq((('/x'):rep(4096) .. '/nvim' + .. ',' .. ('/a'):rep(2048) .. '/nvim' + .. ',' .. ('/b'):rep(2048) .. '/nvim' + .. (',' .. '/c/nvim'):rep(512) + .. ',' .. ('/X'):rep(4096) .. '/nvim/site' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site' + .. ',' .. ('/B'):rep(2048) .. '/nvim/site' + .. (',' .. '/C/nvim/site'):rep(512) + .. ',' .. eval('$VIMRUNTIME') + .. (',' .. '/C/nvim/site/after'):rep(512) + .. ',' .. ('/B'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/X'):rep(4096) .. '/nvim/site/after' + .. (',' .. '/c/nvim/after'):rep(512) + .. ',' .. ('/b'):rep(2048) .. '/nvim/after' + .. ',' .. ('/a'):rep(2048) .. '/nvim/after' + .. ',' .. ('/x'):rep(4096) .. '/nvim/after' + ), meths.get_option('runtimepath')) + meths.command('set runtimepath&') + meths.command('set backupdir&') + meths.command('set directory&') + meths.command('set undodir&') + meths.command('set viewdir&') + eq((('/x'):rep(4096) .. '/nvim' + .. ',' .. ('/a'):rep(2048) .. '/nvim' + .. ',' .. ('/b'):rep(2048) .. '/nvim' + .. (',' .. '/c/nvim'):rep(512) + .. ',' .. ('/X'):rep(4096) .. '/nvim/site' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site' + .. ',' .. ('/B'):rep(2048) .. '/nvim/site' + .. (',' .. '/C/nvim/site'):rep(512) + .. ',' .. eval('$VIMRUNTIME') + .. (',' .. '/C/nvim/site/after'):rep(512) + .. ',' .. ('/B'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/X'):rep(4096) .. '/nvim/site/after' + .. (',' .. '/c/nvim/after'):rep(512) + .. ',' .. ('/b'):rep(2048) .. '/nvim/after' + .. ',' .. ('/a'):rep(2048) .. '/nvim/after' + .. ',' .. ('/x'):rep(4096) .. '/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,' .. ('/X'):rep(4096) .. '/nvim/backup', + meths.get_option('backupdir')) + eq(('/X'):rep(4096) .. '/nvim/swap//', meths.get_option('directory')) + eq(('/X'):rep(4096) .. '/nvim/undo', meths.get_option('undodir')) + eq(('/X'):rep(4096) .. '/nvim/view', meths.get_option('viewdir')) + end) + end) + + describe('with XDG variables that can be expanded', function() + before_each(function() + clear({env={ + XDG_CONFIG_HOME='$XDG_DATA_HOME', + XDG_CONFIG_DIRS='$XDG_DATA_DIRS', + XDG_DATA_HOME='$XDG_CONFIG_HOME', + XDG_DATA_DIRS='$XDG_CONFIG_DIRS', + }}) + end) + + it('are not expanded', function() + eq(('$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/nvim/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/nvim/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ), meths.get_option('runtimepath')) + meths.command('set runtimepath&') + meths.command('set backupdir&') + meths.command('set directory&') + meths.command('set undodir&') + meths.command('set viewdir&') + eq(('$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/nvim/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/nvim/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,$XDG_CONFIG_HOME/nvim/backup', meths.get_option('backupdir')) + eq('$XDG_CONFIG_HOME/nvim/swap//', meths.get_option('directory')) + eq('$XDG_CONFIG_HOME/nvim/undo', meths.get_option('undodir')) + eq('$XDG_CONFIG_HOME/nvim/view', meths.get_option('viewdir')) + end) + end) + + describe('with commas', function() + before_each(function() + clear({env={ + XDG_CONFIG_HOME=', , ,', + XDG_CONFIG_DIRS=',-,-,:-,-,-', + XDG_DATA_HOME=',=,=,', + XDG_DATA_DIRS=',≡,≡,:≡,≡,≡', + }}) + end) + + it('are escaped properly', function() + eq(('\\, \\, \\,/nvim' + .. ',\\,-\\,-\\,/nvim' + .. ',-\\,-\\,-/nvim' + .. ',\\,=\\,=\\,/nvim/site' + .. ',\\,≡\\,≡\\,/nvim/site' + .. ',≡\\,≡\\,≡/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',≡\\,≡\\,≡/nvim/site/after' + .. ',\\,≡\\,≡\\,/nvim/site/after' + .. ',\\,=\\,=\\,/nvim/site/after' + .. ',-\\,-\\,-/nvim/after' + .. ',\\,-\\,-\\,/nvim/after' + .. ',\\, \\, \\,/nvim/after' + ), meths.get_option('runtimepath')) + meths.command('set runtimepath&') + meths.command('set backupdir&') + meths.command('set directory&') + meths.command('set undodir&') + meths.command('set viewdir&') + eq(('\\, \\, \\,/nvim' + .. ',\\,-\\,-\\,/nvim' + .. ',-\\,-\\,-/nvim' + .. ',\\,=\\,=\\,/nvim/site' + .. ',\\,≡\\,≡\\,/nvim/site' + .. ',≡\\,≡\\,≡/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',≡\\,≡\\,≡/nvim/site/after' + .. ',\\,≡\\,≡\\,/nvim/site/after' + .. ',\\,=\\,=\\,/nvim/site/after' + .. ',-\\,-\\,-/nvim/after' + .. ',\\,-\\,-\\,/nvim/after' + .. ',\\, \\, \\,/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,\\,=\\,=\\,/nvim/backup', meths.get_option('backupdir')) + eq('\\,=\\,=\\,/nvim/swap//', meths.get_option('directory')) + eq('\\,=\\,=\\,/nvim/undo', meths.get_option('undodir')) + eq('\\,=\\,=\\,/nvim/view', meths.get_option('viewdir')) + end) + end) +end) -- cgit From 9767b9f00fa1c3aab9068604d965ab5fe33fbac0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Jun 2016 18:22:11 +0300 Subject: functests: Also make sure that `set all&` does not expand --- test/functional/options/defaults_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index cc9944947b..8eec6ad8bf 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -189,6 +189,21 @@ describe('XDG-based defaults', function() eq('$XDG_CONFIG_HOME/nvim/swap//', meths.get_option('directory')) eq('$XDG_CONFIG_HOME/nvim/undo', meths.get_option('undodir')) eq('$XDG_CONFIG_HOME/nvim/view', meths.get_option('viewdir')) + meths.command('set all&') + eq(('$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/nvim/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/nvim/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,$XDG_CONFIG_HOME/nvim/backup', meths.get_option('backupdir')) + eq('$XDG_CONFIG_HOME/nvim/swap//', meths.get_option('directory')) + eq('$XDG_CONFIG_HOME/nvim/undo', meths.get_option('undodir')) + eq('$XDG_CONFIG_HOME/nvim/view', meths.get_option('viewdir')) end) end) -- cgit