1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-24 20:56:11 +02:00

Merge pull request #697 from fuleinist/fix/lsattr-filename-spaces

Fix lsattr parser for filenames with spaces
This commit is contained in:
Kelly Brazil
2026-04-17 10:58:48 -07:00
committed by GitHub
4 changed files with 21 additions and 2 deletions
+5 -1
View File
@@ -149,7 +149,11 @@ def parse(
# attributes file
# --------------e----- /etc/passwd
attributes, file = line.split()
# Use maxsplit=1 to handle filenames with spaces (e.g. "./ok ok ok ok ok")
parts = line.split(maxsplit=1)
if len(parts) != 2:
continue
attributes, file = parts
line_output['file'] = file
for attribute in list(attributes):
attribute_key = ATTRIBUTES.get(attribute)
+1
View File
@@ -0,0 +1 @@
[{"file": "./ok ok ok ok ok", "extents": true}]
+1
View File
@@ -0,0 +1 @@
--------------e----- ./ok ok ok ok ok
+14 -1
View File
@@ -18,6 +18,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/lsattr.out'), 'r', encoding='utf-8') as f:
ubuntu_20_4_lsattr = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/lsattr-spaces.out'), 'r', encoding='utf-8') as f:
ubuntu_20_4_lsattr_spaces = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/lsattr-error.json'), 'r', encoding='utf-8') as f:
ubuntu_20_4_lsattr_error_json = json.loads(f.read())
@@ -28,6 +31,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/lsattr.json'), 'r', encoding='utf-8') as f:
ubuntu_20_4_lsattr_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/lsattr-spaces.json'), 'r', encoding='utf-8') as f:
ubuntu_20_4_lsattr_spaces_json = json.loads(f.read())
def test_lsattr_nodata(self):
"""
Test 'lsattr' with no data
@@ -52,5 +58,12 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(jc.parsers.lsattr.parse(self.ubuntu_20_4_lsattr, quiet=True), self.ubuntu_20_4_lsattr_json)
def test_lsattr_spaces(self):
"""
Test 'lsattr' with filenames containing spaces
"""
self.assertEqual(jc.parsers.lsattr.parse(self.ubuntu_20_4_lsattr_spaces, quiet=True), self.ubuntu_20_4_lsattr_spaces_json)
if __name__ == '__main__':
unittest.main()
unittest.main()