diff --git a/jc/parsers/stat.py b/jc/parsers/stat.py index d071bf31..6ed8e6cc 100644 --- a/jc/parsers/stat.py +++ b/jc/parsers/stat.py @@ -169,7 +169,7 @@ import jc.utils class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.8' + version = '1.9' description = '`stat` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -322,7 +322,7 @@ def parse(data, raw=False, quiet=False): for line in cleandata: value = shlex.split(line) output_line = { - 'file': value[15], + 'file': ' '.join(value[15:]), 'unix_device': value[0], 'inode': value[1], 'flags': value[2], diff --git a/tests/fixtures/osx-10.14.6/stat-filename-with-spaces.json b/tests/fixtures/osx-10.14.6/stat-filename-with-spaces.json new file mode 100644 index 00000000..5b85c4f7 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/stat-filename-with-spaces.json @@ -0,0 +1 @@ +[{"file":"file name with spaces.txt","unix_device":16777220,"inode":161929661,"flags":"-rw-r--r--","links":1,"user":"kbrazil","group":"staff","rdev":0,"size":0,"access_time":"Aug 13 15:03:52 2021","modify_time":"Aug 13 14:37:03 2021","change_time":"Aug 13 14:37:03 2021","birth_time":"Aug 13 14:37:03 2021","block_size":4096,"blocks":0,"unix_flags":"0","access_time_epoch":1628892232,"access_time_epoch_utc":null,"modify_time_epoch":1628890623,"modify_time_epoch_utc":null,"change_time_epoch":1628890623,"change_time_epoch_utc":null,"birth_time_epoch":1628890623,"birth_time_epoch_utc":null}] diff --git a/tests/fixtures/osx-10.14.6/stat-filename-with-spaces.out b/tests/fixtures/osx-10.14.6/stat-filename-with-spaces.out new file mode 100644 index 00000000..083d89fd --- /dev/null +++ b/tests/fixtures/osx-10.14.6/stat-filename-with-spaces.out @@ -0,0 +1,2 @@ +16777220 161929661 -rw-r--r-- 1 kbrazil staff 0 0 "Aug 13 15:03:52 2021" "Aug 13 14:37:03 2021" "Aug 13 14:37:03 2021" "Aug 13 14:37:03 2021" 4096 0 0 file name with spaces.txt + diff --git a/tests/test_stat.py b/tests/test_stat.py index 9d4c84ac..3f8ad60c 100644 --- a/tests/test_stat.py +++ b/tests/test_stat.py @@ -26,6 +26,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/stat.out'), 'r', encoding='utf-8') as f: self.osx_10_14_6_stat = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/stat-filename-with-spaces.out'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_stat_filename_with_spaces = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/stat.out'), 'r', encoding='utf-8') as f: self.freebsd12_stat = f.read() @@ -39,6 +42,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/stat.json'), 'r', encoding='utf-8') as f: self.osx_10_14_6_stat_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/stat-filename-with-spaces.json'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_stat_filename_with_spaces_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/stat.json'), 'r', encoding='utf-8') as f: self.freebsd12_stat_json = json.loads(f.read()) @@ -66,6 +72,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.stat.parse(self.osx_10_14_6_stat, quiet=True), self.osx_10_14_6_stat_json) + def test_stat_filename_with_spaces_osx_10_14_6(self): + """ + Test 'stat' filename with spaces on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.stat.parse(self.osx_10_14_6_stat_filename_with_spaces, quiet=True), self.osx_10_14_6_stat_filename_with_spaces_json) + def test_stat_freebsd12(self): """ Test 'stat /foo/*' on FreeBSD12