Commits

ZyX_I committed 5ca6943

@/os: Fixed NL filenames handling, added tests for NL filenames

Comments (0)

Files changed (3)

plugin/frawor/os.vim

     let path=s:os.path.abspath(a:path)
     let filelist=s:F.globdir(path)
     if s:os.name is 'posix'
-        let filelist+=s:F.globdir(a:path, '.*')
+        let filelist+=s:F.globdir(path, '.*')
     else
         call filter(filelist, '!empty(v:val)')
         return ((a:0)?(filelist):(map(filelist, 'fnamemodify(v:val, ":t")')))
     let nlnum=len(substitute(path, '[^\x0A]', '', 'g'))
     let r=[]
     let i=0
-    let addfragment=""
+    let addfragment=''
     for file in filelist
-        if i<nlnum
+        if i==0 && file[:0] isnot '/'
+            let r[-1].="\n".file
+            continue
+        elseif i<nlnum
             let i+=1
-            let addfragment=file."\n"
+            let addfragment.=file."\n"
             continue
         else
             let file=addfragment.file
             let i=0
-            let addfragment=""
+            let addfragment=''
         endif
         let tail=fnamemodify(file, ':t')
         if tail is '.' || tail is '..'
             continue
         endif
-        if file[0]!=#'/'
-            let r[-1].="\n".file
-        else
-            call add(r, ((a:0)?(file):(tail)))
-        endif
+        call add(r, ((a:0)?(file):(tail)))
     endfor
     return r
 endfunction
                         \   '(shellescape(v:val)))'))
         endif
     else
-        let cmd=join(map(copy(a:command), 'shellescape(v:val)'))
+        let cmd=join(map(copy(a:command), 'shellescape(v:val, 1)'))
     endif
     try
         if a:0
                 return -1
             endif
         endif
-        call system(cmd)
+        execute 'silent! !'.cmd
         redraw!
         return v:shell_error
     finally
Binary file modified.

test/rtp/plugin/os.vim

 endwhile
 unlet sep
 
-call WriteFile("OS: ".os.name." (".os.fullname.")")
-call WriteFile("Path separator: ".os.sep)
-call WriteFile("Line separator: ".esep)
+call WriteFile('OS: '.os.name.' ('.os.fullname.')')
+call WriteFile('Path separator: '.os.sep)
+call WriteFile('Line separator: '.esep)
 unlet esep
 
 let cur0dir=os.path.realpath('.')
-call WriteFile("Curdir: ".os.path.realpath('.'))
+call WriteFile('Curdir: '.os.path.realpath('.'))
 
 call os.mkdir('directory')
 call os.chdir('directory')
 let cur1dir=os.path.realpath('.')
-call WriteFile("Curdir: ".cur1dir)
+call WriteFile('Curdir: '.cur1dir)
 
 new
 call os.chdir('..', 1)
 let cur2dir=os.path.realpath('.')
-call WriteFile("Curdir: ".cur2dir)
+call WriteFile('Curdir: '.cur2dir)
 
 wincmd p
 let cur3dir=os.path.realpath('.')
-call WriteFile("Curdir: ".cur3dir)
+call WriteFile('Curdir: '.cur3dir)
 
 call WriteFile('0=2: '.(cur0dir==cur2dir),
             \  '1=3: '.(cur1dir==cur3dir),)
 W: rmdir
 call os.rmdir('%')
 call WriteFile('%: '.os.path.exists('%'))
+W}
 
+if s:_r.os.name is 'posix'
+    W{ Strange filenames: NL
+    let NL="\n"
+    let aNL="a\n"
+    let NLb="\nb"
+    let aNLb="a\nb"
+    let NLNL="\n\n"
+    let list=[NL, aNL, NLb, aNLb, NLNL]
+    call reverse(map(reverse(list), 'os.path.join(reverse(list[(v:key):]))'))
+    W: Create directories and file
+    call os.makedirs(list[-2])
+    call writefile([], list[-1], 'b')
+    for dir in list
+        call WriteFile(substitute(dir, "\n", 'NL', 'g').':')
+        call WriteFile('    exists: '.os.path.exists(dir))
+        call WriteFile('    isdir: '.os.path.isdir(dir))
+    endfor
+    W: Change directories
+    let olddir=os.path.realpath('.')
+    call os.chdir(list[0])
+    call WriteFile('Curdir: '.os.path.realpath('.'))
+    call os.chdir(olddir)
+    call os.chdir(list[-2])
+    call WriteFile('Curdir: '.os.path.realpath('.'))
+    call os.chdir(olddir)
+    W: Walk
+    let l=[]
+    call os.path.walk('.', s:F.walk, l)
+    call WriteFile(map(l, 'string(v:val)'))
+    call WriteFile(map(os.walk('.'), 'string(v:val)'))
+    W: Remove tree
+    call os.removetree(list[0])
+    call WriteFile(map(os.walk('.'), 'string(v:val)'))
+    W}
+endif
+