File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1649,7 +1649,14 @@ def cmdline(self):
16491649        sep  =  '\x00 '  if  data .endswith ('\x00 ' ) else  ' ' 
16501650        if  data .endswith (sep ):
16511651            data  =  data [:- 1 ]
1652-         return  data .split (sep )
1652+         cmdline  =  data .split (sep )
1653+         # Sometimes last char is a null byte '\0' but the args are 
1654+         # separated by spaces, see: 
1655+         # https://github.com/giampaolo/psutil/ 
1656+         #     issues/1179#issuecomment-552984549 
1657+         if  sep  ==  '\x00 '  and  len (cmdline ) ==  1  and  ' '  in  data :
1658+             cmdline  =  data .split (' ' )
1659+         return  cmdline 
16531660
16541661    @wrap_exceptions  
16551662    def  environ (self ):
Original file line number Diff line number Diff line change @@ -1837,6 +1837,14 @@ def test_cmdline_spaces_mocked(self):
18371837            self .assertEqual (p .cmdline (), ['foo' , 'bar' , '' ])
18381838            assert  m .called 
18391839
1840+     def  test_cmdline_mixed_separators (self ):
1841+         p  =  psutil .Process ()
1842+         fake_file  =  io .StringIO (u ('foo\x20 bar\x00 ' ))
1843+         with  mock .patch ('psutil._common.open' ,
1844+                         return_value = fake_file , create = True ) as  m :
1845+             self .assertEqual (p .cmdline (), ['foo' , 'bar' ])
1846+             assert  m .called 
1847+ 
18401848    def  test_readlink_path_deleted_mocked (self ):
18411849        with  mock .patch ('psutil._pslinux.os.readlink' ,
18421850                        return_value = '/home/foo (deleted)' ):
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments