Patch 8.2.0930
Problem:    Script filetype detection trips over env -S argument.
Solution:   Remove "-S" and "--ignore-environment". (closes #5013)
            Add tests.
Files:      runtime/scripts.vim, src/testdir/test_filetype.vim


*** ../vim-8.2.0929/runtime/scripts.vim 2020-03-06 22:25:52.500279411 +0100
--- runtime/scripts.vim 2020-06-07 21:54:57.293343940 +0200
***************
*** 1,7 ****
  " Vim support file to detect file types in scripts
  "
  " Maintainer: Bram Moolenaar <[email protected]>
! " Last change:        2019 Jun 25
  
  " 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
--- 1,7 ----
  " Vim support file to detect file types in scripts
  "
  " Maintainer: Bram Moolenaar <[email protected]>
! " Last change:        2020 Jun 07
  
  " 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
***************
*** 35,44 ****
  if s:line1 =~# "^#!"
    " A script that starts with "#!".
  
!   " Check for a line like "#!/usr/bin/env VAR=val bash".  Turn it into
    " "#!/usr/bin/bash" to make matching easier.
    if s:line1 =~# '^#!\s*\S*\<env\s'
      let s:line1 = substitute(s:line1, '\S\+=\S\+', '', 'g')
      let s:line1 = substitute(s:line1, '\<env\s\+', '', '')
    endif
  
--- 35,46 ----
  if s:line1 =~# "^#!"
    " A script that starts with "#!".
  
!   " Check for a line like "#!/usr/bin/env {options} bash".  Turn it into
    " "#!/usr/bin/bash" to make matching easier.
+   " Recognize only a few {options} that are commonly used.
    if s:line1 =~# '^#!\s*\S*\<env\s'
      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\+', '', '')
    endif
  
*** ../vim-8.2.0929/src/testdir/test_filetype.vim       2020-06-07 
20:07:40.133852226 +0200
--- src/testdir/test_filetype.vim       2020-06-07 21:57:47.764735252 +0200
***************
*** 607,615 ****
        \ 'yaml': [['%YAML 1.2']],
        \ }
  
! func Test_script_detection()
    filetype on
!   for [ft, files] in items(s:script_checks)
      for file in files
        call writefile(file, 'Xtest')
        split Xtest
--- 607,625 ----
        \ 'yaml': [['%YAML 1.2']],
        \ }
  
! " 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
!   for [ft, files] in items(a:test_dict)
      for file in files
        call writefile(file, 'Xtest')
        split Xtest
***************
*** 621,626 ****
--- 631,641 ----
    filetype off
  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()
    call feedkeys(":setfiletype java\<C-A>\<C-B>\"\<CR>", 'tx')
    call assert_equal('"setfiletype java javacc javascript javascriptreact', @:)
*** ../vim-8.2.0929/src/version.c       2020-06-07 21:31:14.778405833 +0200
--- src/version.c       2020-06-07 21:57:05.572884274 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     930,
  /**/

-- 
Back up my hard drive?  I can't find the reverse switch!

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202006071959.057JxLOV133988%40masaka.moolenaar.net.

Raspunde prin e-mail lui