Skip to content

Commit b5e18f2

Browse files
committed
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 #5013) Add tests.
1 parent cc61303 commit b5e18f2

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

runtime/scripts.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim support file to detect file types in scripts
22
"
33
" Maintainer: Bram Moolenaar <[email protected]>
4-
" Last change: 2020 Mar 06
4+
" Last change: 2020 Jun 07
55

66
" This file is called by an autocommand for every file that has just been
77
" loaded into a buffer. It checks if the type of file can be recognized by
@@ -35,10 +35,12 @@ let s:line1 = getline(1)
3535
if s:line1 =~# "^#!"
3636
" A script that starts with "#!".
3737

38-
" Check for a line like "#!/usr/bin/env VAR=val bash". Turn it into
38+
" Check for a line like "#!/usr/bin/env {options} bash". Turn it into
3939
" "#!/usr/bin/bash" to make matching easier.
40+
" Recognize only a few {options} that are commonly used.
4041
if s:line1 =~# '^#!\s*\S*\<env\s'
4142
let s:line1 = substitute(s:line1, '\S\+=\S\+', '', 'g')
43+
let s:line1 = substitute(s:line1, '\(-[iS]\|--ignore-environment\|--split-string\)', '', '')
4244
let s:line1 = substitute(s:line1, '\<env\s\+', '', '')
4345
endif
4446

src/testdir/test_filetype.vim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,19 @@ let s:script_checks = {
607607
\ 'yaml': [['%YAML 1.2']],
608608
\ }
609609

610-
func Test_script_detection()
610+
" Various forms of "env" optional arguments.
611+
let s:script_env_checks = {
612+
\ 'perl': [['#!/usr/bin/env VAR=val perl']],
613+
\ 'scala': [['#!/usr/bin/env VAR=val VVAR=vval scala']],
614+
\ 'awk': [['#!/usr/bin/env VAR=val -i awk']],
615+
\ 'scheme': [['#!/usr/bin/env VAR=val --ignore-environment scheme']],
616+
\ 'python': [['#!/usr/bin/env VAR=val -S python -w -T']],
617+
\ 'wml': [['#!/usr/bin/env VAR=val --split-string wml']],
618+
\ }
619+
620+
func Run_script_detection(test_dict)
611621
filetype on
612-
for [ft, files] in items(s:script_checks)
622+
for [ft, files] in items(a:test_dict)
613623
for file in files
614624
call writefile(file, 'Xtest')
615625
split Xtest
@@ -621,6 +631,11 @@ func Test_script_detection()
621631
filetype off
622632
endfunc
623633

634+
func Test_script_detection()
635+
call Run_script_detection(s:script_checks)
636+
call Run_script_detection(s:script_env_checks)
637+
endfunc
638+
624639
func Test_setfiletype_completion()
625640
call feedkeys(":setfiletype java\<C-A>\<C-B>\"\<CR>", 'tx')
626641
call assert_equal('"setfiletype java javacc javascript javascriptreact', @:)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
930,
757759
/**/
758760
929,
759761
/**/

0 commit comments

Comments
 (0)