diff --git a/jc/parsers/dir.py b/jc/parsers/dir.py index d522d94a..705c04b3 100644 --- a/jc/parsers/dir.py +++ b/jc/parsers/dir.py @@ -183,8 +183,8 @@ def parse(data, raw=False, quiet=False): if jc.utils.has_data(data): for line in data.splitlines(): - if line.startswith(" Directory of"): - parent_dir = line.lstrip(" Directory of ") + if line.startswith(" Directory of "): + parent_dir = line[len(" Directory of "):] continue # skip lines that don't start with a date if not re.match(r'^\d{2}/\d{2}/\d{4}', line): diff --git a/tests/test_dir.py b/tests/test_dir.py index 995a7cd7..8829c9c0 100644 --- a/tests/test_dir.py +++ b/tests/test_dir.py @@ -95,6 +95,25 @@ class MyTests(unittest.TestCase): self.assertEqual(jc.parsers.dir.parse(self.windows_10_dir_S, quiet=True), self.windows_10_dir_S_json) + def test_dir_drive_letter_d(self): + """ + Test that the D: drive letter is not stripped from the parent path. + Regression test: lstrip(" Directory of ") strips any char in the set + {' ','D','i','r','e','c','t','o','y','f'}, which incorrectly removes + the 'D' from 'D:\\'. + """ + data = ( + ' Volume in drive D has no label.\r\n' + ' Volume Serial Number is 1234-5678\r\n' + '\r\n' + ' Directory of D:\\Users\\testuser\r\n' + '\r\n' + '03/24/2021 03:15 PM