mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.0930: script filetype detection trips over env -S argument
Problem: Script filetype detection trips over env -S argument.
Solution: Remove "-S" and "--ignore-environment". (closes vim/vim#5013)
Add tests.
b5e18f29fa
This commit is contained in:
parent
150168b881
commit
9d565c5ba3
@ -1,7 +1,7 @@
|
|||||||
" Vim support file to detect file types in scripts
|
" Vim support file to detect file types in scripts
|
||||||
"
|
"
|
||||||
" Maintainer: Bram Moolenaar <Bram@vim.org>
|
" Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||||
" Last change: 2019 Jun 25
|
" Last change: 2020 Jun 07
|
||||||
|
|
||||||
" This file is called by an autocommand for every file that has just been
|
" This file is called by an autocommand for every file that has just been
|
||||||
" loaded into a buffer. It checks if the type of file can be recognized by
|
" loaded into a buffer. It checks if the type of file can be recognized by
|
||||||
@ -35,10 +35,12 @@ let s:line1 = getline(1)
|
|||||||
if s:line1 =~# "^#!"
|
if s:line1 =~# "^#!"
|
||||||
" A script that starts with "#!".
|
" A script that starts with "#!".
|
||||||
|
|
||||||
" Check for a line like "#!/usr/bin/env VAR=val bash". Turn it into
|
" Check for a line like "#!/usr/bin/env {options} bash". Turn it into
|
||||||
" "#!/usr/bin/bash" to make matching easier.
|
" "#!/usr/bin/bash" to make matching easier.
|
||||||
|
" Recognize only a few {options} that are commonly used.
|
||||||
if s:line1 =~# '^#!\s*\S*\<env\s'
|
if s:line1 =~# '^#!\s*\S*\<env\s'
|
||||||
let s:line1 = substitute(s:line1, '\S\+=\S\+', '', 'g')
|
let s:line1 = substitute(s:line1, '\S\+=\S\+', '', 'g')
|
||||||
|
let s:line1 = substitute(s:line1, '\(-[iS]\|--ignore-environment\|--split-string\)', '', '')
|
||||||
let s:line1 = substitute(s:line1, '\<env\s\+', '', '')
|
let s:line1 = substitute(s:line1, '\<env\s\+', '', '')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -606,9 +606,19 @@ let s:script_checks = {
|
|||||||
\ 'yaml': [['%YAML 1.2']],
|
\ 'yaml': [['%YAML 1.2']],
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
func Test_script_detection()
|
" Various forms of "env" optional arguments.
|
||||||
|
let s:script_env_checks = {
|
||||||
|
\ 'perl': [['#!/usr/bin/env VAR=val perl']],
|
||||||
|
\ 'scala': [['#!/usr/bin/env VAR=val VVAR=vval scala']],
|
||||||
|
\ 'awk': [['#!/usr/bin/env VAR=val -i awk']],
|
||||||
|
\ 'scheme': [['#!/usr/bin/env VAR=val --ignore-environment scheme']],
|
||||||
|
\ 'python': [['#!/usr/bin/env VAR=val -S python -w -T']],
|
||||||
|
\ 'wml': [['#!/usr/bin/env VAR=val --split-string wml']],
|
||||||
|
\ }
|
||||||
|
|
||||||
|
func Run_script_detection(test_dict)
|
||||||
filetype on
|
filetype on
|
||||||
for [ft, files] in items(s:script_checks)
|
for [ft, files] in items(a:test_dict)
|
||||||
for file in files
|
for file in files
|
||||||
call writefile(file, 'Xtest')
|
call writefile(file, 'Xtest')
|
||||||
split Xtest
|
split Xtest
|
||||||
@ -620,6 +630,11 @@ func Test_script_detection()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_script_detection()
|
||||||
|
call Run_script_detection(s:script_checks)
|
||||||
|
call Run_script_detection(s:script_env_checks)
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_setfiletype_completion()
|
func Test_setfiletype_completion()
|
||||||
call feedkeys(":setfiletype java\<C-A>\<C-B>\"\<CR>", 'tx')
|
call feedkeys(":setfiletype java\<C-A>\<C-B>\"\<CR>", 'tx')
|
||||||
call assert_equal('"setfiletype java javacc javascript javascriptreact', @:)
|
call assert_equal('"setfiletype java javacc javascript javascriptreact', @:)
|
||||||
|
Loading…
Reference in New Issue
Block a user