diff --git a/CHANGELOG b/CHANGELOG index 263cede2..a3fa9967 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ jc changelog - Add git log command streaming parser - Add top -b command parser tested on linux - Add top -b command streaming parser tested on linux +- Fix df command parser for rare instances when a newline is found at the end - Allow jc to pip install on unsupported python version 3.6 - Fix asciitable-m parser to skip some rows that contain column separator characters in cell data. A warning message will be printed to STDOUT diff --git a/docs/parsers/df.md b/docs/parsers/df.md index 90fbb415..9da885dc 100644 --- a/docs/parsers/df.md +++ b/docs/parsers/df.md @@ -120,4 +120,4 @@ Returns: ### Parser Information Compatibility: linux, darwin, freebsd -Version 1.9 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/jc/parsers/df.py b/jc/parsers/df.py index a6b1fe55..4907041c 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -99,7 +99,7 @@ import jc.parsers.universal class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.9' + version = '1.10' description = '`df` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -208,7 +208,9 @@ def parse(data, raw=False, quiet=False): jc.utils.compatibility(__name__, info.compatible, quiet) jc.utils.input_type_check(data) - cleandata = data.splitlines() + # remove blank lines + cleandata = list(filter(None, data.splitlines())) + fix_data = [] raw_output = [] filesystem_map = {} diff --git a/tests/test_df.py b/tests/test_df.py index 0736e95b..2595dc71 100644 --- a/tests/test_df.py +++ b/tests/test_df.py @@ -125,6 +125,13 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.df.parse(self.generic_df_long_filesystem, quiet=True), self.generic_df_long_filesystem_json) + def test_df_centos_7_7_trailing_newline(self): + """ + Test plain 'df' on Centos 7.7 with a trailing newline + """ + cmd_output = self.centos_7_7_df + '\n' + self.assertEqual(jc.parsers.df.parse(cmd_output, quiet=True), self.centos_7_7_df_json) + if __name__ == '__main__': unittest.main()