From 72a0016bd833699c3819baa899f335f75b8c1943 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 20 Feb 2020 15:38:45 -0800 Subject: [PATCH 01/13] use link to anchor for Parsers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60f9923e..6661c2b3 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JC JSON CLI output utility -`jc` is used to JSONify the output of many standard linux cli tools and file types for easier parsing in scripts. See the **Parsers** section for supported commands. +`jc` is used to JSONify the output of many standard linux cli tools and file types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands. This allows further command line processing of output with tools like `jq` simply by piping commands: ``` From c8dac32df8102c2b782e87d55bb95ca2d9490185 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 13:05:35 -0800 Subject: [PATCH 02/13] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6661c2b3..fb0a5ab0 100755 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ $ jc ls -l /usr/bin | jq '.[] | select(.size > 50000000)' "date": "Aug 14 19:41" } ``` -The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary instead of JSON: +The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary, or list of dictionaries, instead of JSON: ``` >>> import jc.parsers.ls >>> From 964868c8aff99edf37b0db41c7d16f8b84ac4704 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 15:19:43 -0800 Subject: [PATCH 03/13] add support for newlines in filenames (only with ls -l) --- docs/parsers/ls.md | 5 ++++- jc/parsers/ls.py | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/parsers/ls.md b/docs/parsers/ls.md index d37b255c..aed2b828 100644 --- a/docs/parsers/ls.md +++ b/docs/parsers/ls.md @@ -1,12 +1,15 @@ # jc.parsers.ls jc - JSON CLI output utility ls Parser +Note: The -l option of ls should be used to correctly parse filenames that include newline characters. + Since ls does not encode newlines in filenames when outputting to a pipe it will cause jc to see + multiple files instead of a single file if -l is not used. + Usage: specify --ls as the first argument if the piped input is coming from ls ls options supported: - - None - laR --time-style=full-iso - h file sizes will be available in text form with -r but larger file sizes diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 12477099..d678494f 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -1,11 +1,14 @@ """jc - JSON CLI output utility ls Parser +Note: The -l option of ls should be used to correctly parse filenames that include newline characters. + Since ls does not encode newlines in filenames when outputting to a pipe it will cause jc to see + multiple files instead of a single file if -l is not used. + Usage: specify --ls as the first argument if the piped input is coming from ls ls options supported: - - None - laR --time-style=full-iso - h file sizes will be available in text form with -r but larger file sizes @@ -145,7 +148,7 @@ import jc.utils class info(): - version = '1.1' + version = '1.2' description = 'ls command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -233,6 +236,8 @@ def parse(data, raw=False, quiet=False): # Pop following total line linedata.pop(0) + new_section = False + if linedata: # Check if -l was used to parse extra data if re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]): @@ -241,15 +246,24 @@ def parse(data, raw=False, quiet=False): parsed_line = entry.split(maxsplit=8) - if not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry) \ + if new_section \ + and not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry) \ and entry.endswith(':'): parent = entry[:-1] + new_section = False continue if re.match('^total [0-9]+', entry): continue if entry == '': + new_section = True + continue + + # fixup for filenames with newlines + if not new_section \ + and not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry): + raw_output[-1]['filename'] = raw_output[-1]['filename'] + '\n' + entry continue # split filenames and links From 116e07f1614b4a45eb58ffcfe20b5efa71c473a8 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 16:38:29 -0800 Subject: [PATCH 04/13] fixes for multiple consecutive newlines and trailing newlines in filenames --- jc/parsers/ls.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index d678494f..747fb8de 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -246,18 +246,17 @@ def parse(data, raw=False, quiet=False): parsed_line = entry.split(maxsplit=8) - if new_section \ - and not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry) \ + if not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry) \ and entry.endswith(':'): parent = entry[:-1] - new_section = False + new_section = True + + # fixup to remove trailing \n in previous entry + raw_output[-1]['filename'] = raw_output[-1]['filename'][:-1] continue if re.match('^total [0-9]+', entry): - continue - - if entry == '': - new_section = True + new_section = False continue # fixup for filenames with newlines From 573b27946474276592ee7494689ce9a88f5a05f7 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 17:01:12 -0800 Subject: [PATCH 05/13] fixup for filenames that start with a newline character --- jc/parsers/ls.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 747fb8de..8fd33017 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -266,7 +266,11 @@ def parse(data, raw=False, quiet=False): continue # split filenames and links - filename_field = parsed_line[8].split(' -> ') + if len(parsed_line) == 9: + filename_field = parsed_line[8].split(' -> ') + else: + # in case of filenames starting with a newline character + filename_field = [''] # create list of dictionaries output_line['filename'] = filename_field[0] From b5a0d650b128d8af81bb14dd5d007349529cb66f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 17:01:33 -0800 Subject: [PATCH 06/13] ls output with newlines --- tests/fixtures/osx-10.14.6/ls-newlines.out | 151 +++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/fixtures/osx-10.14.6/ls-newlines.out diff --git a/tests/fixtures/osx-10.14.6/ls-newlines.out b/tests/fixtures/osx-10.14.6/ls-newlines.out new file mode 100644 index 00000000..a792207e --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-newlines.out @@ -0,0 +1,151 @@ +total 584 +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:55 + + +three newlines start this file +drwxr-xr-x 3 root wheel 96 Feb 24 12:13 MacAgent +-rw------- 1 root wheel 0 Feb 24 16:33 _Library_Application Support_Fortinet_FortiClient_data__vir_high +-rw------- 1 root wheel 0 Feb 24 16:33 _Library_Application Support_Fortinet_FortiClient_tmp_avsig_delata_vir_high +srwxr-xr-x 1 kbrazil wheel 0 Feb 20 14:41 centosserial +-rw-r--r-- 1 root wheel 382 Feb 20 14:41 centosserial.sh.log +drwx------ 3 kbrazil wheel 96 Feb 7 23:32 com.apple.launchd.ZRwqedKmO9 +drwx------ 3 kbrazil wheel 96 Feb 7 23:32 com.apple.launchd.xPCDEP69Cl +srwxrwxrwx 1 kbrazil wheel 0 Feb 7 23:32 fctvpnctl.sock +srw------- 1 kbrazil wheel 0 Feb 7 23:32 fctvpnctl.sock_501 +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:58 ls-newlines.out +drwxr-xr-x 10 kbrazil wheel 320 Feb 24 16:58 lstest +srw-rw-rw- 1 root wheel 0 Feb 7 23:31 olisne-WY4G9IZafUNsloCollectorServicePipe +-rwx------ 1 root wheel 535 Feb 22 18:56 scriptcode.0JeYTA +-rwx------ 1 root wheel 531 Feb 22 19:19 scriptcode.0d9OX9 +-rwx------ 1 root wheel 535 Feb 24 12:12 scriptcode.0jvSGh +-rwx------ 1 root wheel 3312 Feb 20 17:43 scriptcode.26L6Aw +-rwx------ 1 root wheel 311 Feb 22 18:56 scriptcode.2KJ0DB +-rwx------ 1 root wheel 316 Feb 21 18:10 scriptcode.3iQbCH +-rwx------ 1 root wheel 1068 Feb 21 18:10 scriptcode.47tsJK +-rwx------ 1 root wheel 316 Feb 24 12:12 scriptcode.5EGutx +-rwx------ 1 root wheel 279 Feb 24 12:12 scriptcode.73zg3m +-rwx------ 1 root wheel 920 Feb 22 19:19 scriptcode.7EKhVr +-rwx------ 1 root wheel 408 Feb 22 19:19 scriptcode.7XsHV0 +-rwx------ 1 root wheel 531 Feb 20 17:43 scriptcode.7lVOvs +-rwx------ 1 root wheel 1068 Feb 20 17:43 scriptcode.AHABAG +-rwx------ 1 root wheel 316 Feb 20 17:43 scriptcode.CnQHRy +-rwx------ 1 root wheel 279 Feb 21 18:41 scriptcode.FEStzN +-rwx------ 1 root wheel 277 Feb 20 17:43 scriptcode.FY7cUj +-rwx------ 1 root wheel 1292 Feb 20 17:43 scriptcode.GY4L8Z +-rwx------ 1 root wheel 535 Feb 20 17:05 scriptcode.Gz2pae +-rwx------ 1 root wheel 311 Feb 21 18:09 scriptcode.GzIQzf +-rwx------ 1 root wheel 920 Feb 24 12:12 scriptcode.HPloGp +-rwx------ 1 root wheel 531 Feb 24 12:12 scriptcode.HtJdie +-rwx------ 1 root wheel 311 Feb 24 12:11 scriptcode.Ihm1Oo +-rwx------ 1 root wheel 277 Feb 22 19:19 scriptcode.IkV9ka +-rwx------ 1 root wheel 3312 Feb 24 12:12 scriptcode.KKN22F +-rwx------ 1 root wheel 279 Feb 24 12:12 scriptcode.Kx84Te +-rwx------ 1 root wheel 408 Feb 24 12:12 scriptcode.LyuE2u +-rwx------ 1 root wheel 400 Feb 21 18:41 scriptcode.N2AhIg +-rwx------ 1 root wheel 1208 Feb 24 12:12 scriptcode.Nqmmg7 +-rwx------ 1 root wheel 3312 Feb 21 18:10 scriptcode.OHRPTO +-rwx------ 1 root wheel 277 Feb 24 12:12 scriptcode.OQCX7n +-rwx------ 1 root wheel 535 Feb 21 18:41 scriptcode.PoKNUA +-rwx------ 1 root wheel 531 Feb 22 19:19 scriptcode.R2XvfH +-rwx------ 1 root wheel 408 Feb 21 18:10 scriptcode.R4JK3n +-rwx------ 1 root wheel 1292 Feb 21 18:41 scriptcode.RgJYtc +-rwx------ 1 root wheel 531 Feb 20 17:43 scriptcode.SeUnOY +-rwx------ 1 root wheel 316 Feb 22 19:19 scriptcode.SmpfaH +-rwx------ 1 root wheel 1208 Feb 21 18:41 scriptcode.Sqk4gn +-rwx------ 1 root wheel 311 Feb 21 18:09 scriptcode.SxoG8F +-rwx------ 1 root wheel 531 Feb 24 12:12 scriptcode.ThENy0 +-rwx------ 1 root wheel 311 Feb 22 18:56 scriptcode.TjBafP +-rwx------ 1 root wheel 279 Feb 20 17:43 scriptcode.VYNiW2 +-rwx------ 1 root wheel 535 Feb 24 12:11 scriptcode.Yyqf85 +-rwx------ 1 root wheel 535 Feb 22 19:19 scriptcode.aVTtu2 +-rwx------ 1 root wheel 1208 Feb 20 17:43 scriptcode.czs9l6 +-rwx------ 1 root wheel 920 Feb 20 17:43 scriptcode.eFVE3D +-rwx------ 1 root wheel 1292 Feb 24 12:12 scriptcode.f88eGZ +-rwx------ 1 root wheel 282 Feb 24 12:12 scriptcode.flB4nR +-rwx------ 1 root wheel 277 Feb 21 18:41 scriptcode.iMzN8Y +-rwx------ 1 root wheel 535 Feb 20 17:43 scriptcode.iPaXLd +-rwx------ 1 root wheel 279 Feb 21 18:41 scriptcode.jkaeC8 +-rwx------ 1 root wheel 1292 Feb 22 19:19 scriptcode.k0Qc64 +-rwx------ 1 root wheel 279 Feb 20 17:43 scriptcode.kH4nP3 +-rwx------ 1 root wheel 282 Feb 20 17:43 scriptcode.l0Wcmj +-rwx------ 1 root wheel 311 Feb 24 12:11 scriptcode.lWzSJu +-rwx------ 1 root wheel 279 Feb 22 19:19 scriptcode.m1wgPP +-rwx------ 1 root wheel 1208 Feb 22 19:19 scriptcode.mG7NEw +-rwx------ 1 root wheel 531 Feb 21 18:41 scriptcode.mfGENQ +-rwx------ 1 root wheel 1068 Feb 24 12:12 scriptcode.n4urXg +-rwx------ 1 root wheel 535 Feb 21 18:09 scriptcode.n5Hn9m +-rwx------ 1 root wheel 282 Feb 21 18:10 scriptcode.nggGXs +-rwx------ 1 root wheel 400 Feb 24 12:12 scriptcode.obdjU7 +-rwx------ 1 root wheel 1068 Feb 22 19:19 scriptcode.pIBQku +-rwx------ 1 root wheel 400 Feb 22 19:19 scriptcode.pmiMa5 +-rwx------ 1 root wheel 400 Feb 20 17:43 scriptcode.qd2MtX +-rwx------ 1 root wheel 311 Feb 20 17:05 scriptcode.sF2VTO +-rwx------ 1 root wheel 920 Feb 21 18:41 scriptcode.sWaDJU +-rwx------ 1 root wheel 408 Feb 20 17:43 scriptcode.tb9thN +-rwx------ 1 root wheel 3312 Feb 22 19:19 scriptcode.v5rHnt +-rwx------ 1 root wheel 531 Feb 21 18:41 scriptcode.xSmYzD +-rwx------ 1 root wheel 311 Feb 20 17:05 scriptcode.xztElJ +-rwx------ 1 root wheel 282 Feb 22 19:19 scriptcode.z1R5gD +-rwx------ 1 root wheel 279 Feb 22 19:19 scriptcode.zPNZQP +drwx------ 3 kbrazil wheel 96 Feb 13 16:44 vmware-kbrazil + +./MacAgent: +total 416 +-rw-r--r-- 1 root wheel 211848 Feb 24 12:13 vulscanOut.xml + +./com.apple.launchd.ZRwqedKmO9: +total 0 +srw-rw-rw- 1 kbrazil wheel 0 Feb 7 23:32 Render + +./com.apple.launchd.xPCDEP69Cl: +total 0 +srw-rw-rw- 1 kbrazil wheel 0 Feb 7 23:32 Listeners + +./lstest: +total 0 +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:58 + + +combo of +newlines + +inside +and trailing + +this file + + + + + + +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:55 + + +three newlines start this file +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:42 +this file has a newline in the beginning +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 14:56 another filename with +multiple +newline characters +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:35 filename with + +two newlines and two trailing newlines + + +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 14:55 filename with a +newline character +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 14:56 regularfile +-rw-r--r-- 1 kbrazil wheel 0 Feb 24 15:44 this filename has + + + +four newlines in it + +./vmware-kbrazil: +total 0 +drwx------ 3 kbrazil wheel 96 Feb 20 14:41 mksctrl + +./vmware-kbrazil/mksctrl: +total 0 +srwxr-xr-x 1 kbrazil wheel 0 Feb 20 14:41 mksctrl-0000002818-000-39aec79d From c7b7f1a5dcf77a1f4c23ef6bbf5683fd1a055f72 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 17:24:56 -0800 Subject: [PATCH 07/13] fix for files with newlines in naked ls --- jc/parsers/ls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 8fd33017..335efd23 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -296,7 +296,7 @@ def parse(data, raw=False, quiet=False): next_is_parent = True continue - if next_is_parent: + if next_is_parent and entry.endswith(':'): parent = entry[:-1] next_is_parent = False continue From 961696c963215a9dab56113ff89f21a6e9739df6 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 17:47:31 -0800 Subject: [PATCH 08/13] add a warning if newlines are detected in naked ls --- jc/parsers/ls.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 335efd23..5686ff5c 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -236,6 +236,7 @@ def parse(data, raw=False, quiet=False): # Pop following total line linedata.pop(0) + warned = False new_section = False if linedata: @@ -301,6 +302,10 @@ def parse(data, raw=False, quiet=False): next_is_parent = False continue + if not quiet and next_is_parent and not entry.endswith(':') and not warned: + jc.utils.warning_message('Newline characters detected. Filenames probably corrupted. Use ls -l instead.') + warned = True + output_line['filename'] = entry if parent: From 22a35f41bf9c404d3532611f5929143d04b10010 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 17:50:56 -0800 Subject: [PATCH 09/13] move variables to top --- jc/parsers/ls.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 5686ff5c..ec0dd6f1 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -218,6 +218,10 @@ def parse(data, raw=False, quiet=False): jc.utils.compatibility(__name__, info.compatible) raw_output = [] + warned = False + parent = '' + next_is_parent = False + new_section = False linedata = data.splitlines() @@ -226,9 +230,6 @@ def parse(data, raw=False, quiet=False): if re.match('^total [0-9]+', linedata[0]): linedata.pop(0) - parent = '' - next_is_parent = False - # Look for parent line if glob or -R is used if not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \ and linedata[0].endswith(':'): @@ -236,9 +237,6 @@ def parse(data, raw=False, quiet=False): # Pop following total line linedata.pop(0) - warned = False - new_section = False - if linedata: # Check if -l was used to parse extra data if re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]): From 6ae50054e2e8c7ca730013b43062eedc230c0ad4 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 24 Feb 2020 20:30:44 -0800 Subject: [PATCH 10/13] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb0a5ab0..dee71e34 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JC JSON CLI output utility -`jc` is used to JSONify the output of many standard linux cli tools and file types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands. +`jc` is used to JSONify the output of many standard linux cli tools and file types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and file types. This allows further command line processing of output with tools like `jq` simply by piping commands: ``` From 873b5ba8acf599d083d6031b818d5fca83cbca9e Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 27 Feb 2020 09:36:57 -0800 Subject: [PATCH 11/13] move examples to bottom --- README.md | 58 ++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index dee71e34..d5c8f0b7 100755 --- a/README.md +++ b/README.md @@ -129,6 +129,32 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio - `-q` quiet mode. Suppresses warning messages - `-r` raw output. Provides a more literal JSON output with all values as text and no additional sematic processing +## Contributions +Feel free to add/improve code or parsers! You can use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) parser as a template and submit your parser with a pull request. + +## Compatibility +Some parsers like `ls`, `ps`, `dig`, etc. will work on any platform. Other parsers that are platform-specific will generate a warning message if they are used on an unsupported platform. To see all parser information, including compatibility, run `jc -ap`. + + +You may still use a parser on an unsupported platform - for example, you may want to parse a file with linux `lsof` output on an OSX laptop. In that case you can suppress the warning message with the `-q` cli option or the `quiet=True` function parameter in `parse()`: + +``` +$ cat lsof.out | jc --lsof -q +``` + +Tested on: +- Centos 7.7 +- Ubuntu 18.4 +- OSX 10.11.6 +- OSX 10.14.6 + +## Acknowledgments +- `ifconfig-parser` module from https://github.com/KnightWhoSayNi/ifconfig-parser +- `xmltodict` module from https://github.com/martinblech/xmltodict by Martín Blech +- `ruamel.yaml` library from https://pypi.org/project/ruamel.yaml by Anthon van der Neut +- Parsing code from Conor Heine at https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 adapted for some parsers +- Excellent constructive feedback from Ilya Sher (https://github.com/ilyash-b) + ## Examples ### arp ``` @@ -1867,34 +1893,4 @@ $ cat istio.yaml | jc --yaml -p } } ] -``` -## TODO -Future parsers: -- /proc files -- /sys files - -## Contributions -Feel free to add/improve code or parsers! You can use the `jc/parsers/foo.py` parser as a template and submit your parser with a pull request. - -## Compatibility -Some parsers like `ls`, `ps`, `dig`, etc. will work on any platform. Other parsers that are platform-specific will generate a warning message if they are used on an unsupported platform. To see all parser information, including compatibility, run `jc -ap`. - - -You may still use a parser on an unsupported platform - for example, you may want to parse a file with linux `lsof` output on an OSX laptop. In that case you can suppress the warning message with the `-q` cli option or the `quiet=True` function parameter in `parse()`: - -``` -$ cat lsof.out | jc --lsof -q -``` - -Tested on: -- Centos 7.7 -- Ubuntu 18.4 -- OSX 10.11.6 -- OSX 10.14.6 - -## Acknowledgments -- `ifconfig-parser` module from https://github.com/KnightWhoSayNi/ifconfig-parser -- `xmltodict` module from https://github.com/martinblech/xmltodict by Martín Blech -- `ruamel.yaml` library from https://pypi.org/project/ruamel.yaml by Anthon van der Neut -- Parsing code from Conor Heine at https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 adapted for some parsers -- Excellent constructive feedback from Ilya Sher (https://github.com/ilyash-b) +``` \ No newline at end of file From ad61e6bc81177a2add7d052bf1ddec5f1b3f2976 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 27 Feb 2020 10:48:09 -0800 Subject: [PATCH 12/13] add ls tests for filenames with newline characters --- tests/fixtures/centos-7.7/ls-R-newlines.json | 1 + tests/fixtures/centos-7.7/ls-R-newlines.out | 43 +++++ tests/fixtures/centos-7.7/ls-l-newlines.json | 1 + tests/fixtures/centos-7.7/ls-l-newlines.out | 34 ++++ tests/fixtures/centos-7.7/ls-lR-newlines.json | 1 + tests/fixtures/centos-7.7/ls-lR-newlines.out | 45 +++++ tests/fixtures/centos-7.7/ls-newlines.json | 1 + tests/fixtures/centos-7.7/ls-newlines.out | 33 ++++ tests/fixtures/create_fixtures.sh | 15 ++ tests/fixtures/osx-10.14.6/ls-R-newlines.json | 1 + tests/fixtures/osx-10.14.6/ls-R-newlines.out | 36 ++++ tests/fixtures/osx-10.14.6/ls-l-newlines.json | 1 + tests/fixtures/osx-10.14.6/ls-l-newlines.out | 34 ++++ .../fixtures/osx-10.14.6/ls-lR-newlines.json | 1 + tests/fixtures/osx-10.14.6/ls-lR-newlines.out | 38 ++++ tests/fixtures/osx-10.14.6/ls-newlines.json | 1 + tests/fixtures/osx-10.14.6/ls-newlines.out | 166 +++--------------- .../fixtures/ubuntu-18.04/ls-R-newlines.json | 1 + tests/fixtures/ubuntu-18.04/ls-R-newlines.out | 40 +++++ .../fixtures/ubuntu-18.04/ls-l-newlines.json | 1 + tests/fixtures/ubuntu-18.04/ls-l-newlines.out | 34 ++++ .../fixtures/ubuntu-18.04/ls-lR-newlines.json | 1 + .../fixtures/ubuntu-18.04/ls-lR-newlines.out | 42 +++++ tests/fixtures/ubuntu-18.04/ls-newlines.json | 1 + tests/fixtures/ubuntu-18.04/ls-newlines.out | 33 ++++ tests/test_ls.py | 144 +++++++++++++++ 26 files changed, 607 insertions(+), 142 deletions(-) create mode 100644 tests/fixtures/centos-7.7/ls-R-newlines.json create mode 100644 tests/fixtures/centos-7.7/ls-R-newlines.out create mode 100644 tests/fixtures/centos-7.7/ls-l-newlines.json create mode 100644 tests/fixtures/centos-7.7/ls-l-newlines.out create mode 100644 tests/fixtures/centos-7.7/ls-lR-newlines.json create mode 100644 tests/fixtures/centos-7.7/ls-lR-newlines.out create mode 100644 tests/fixtures/centos-7.7/ls-newlines.json create mode 100644 tests/fixtures/centos-7.7/ls-newlines.out create mode 100644 tests/fixtures/osx-10.14.6/ls-R-newlines.json create mode 100644 tests/fixtures/osx-10.14.6/ls-R-newlines.out create mode 100644 tests/fixtures/osx-10.14.6/ls-l-newlines.json create mode 100644 tests/fixtures/osx-10.14.6/ls-l-newlines.out create mode 100644 tests/fixtures/osx-10.14.6/ls-lR-newlines.json create mode 100644 tests/fixtures/osx-10.14.6/ls-lR-newlines.out create mode 100644 tests/fixtures/osx-10.14.6/ls-newlines.json create mode 100644 tests/fixtures/ubuntu-18.04/ls-R-newlines.json create mode 100644 tests/fixtures/ubuntu-18.04/ls-R-newlines.out create mode 100644 tests/fixtures/ubuntu-18.04/ls-l-newlines.json create mode 100644 tests/fixtures/ubuntu-18.04/ls-l-newlines.out create mode 100644 tests/fixtures/ubuntu-18.04/ls-lR-newlines.json create mode 100644 tests/fixtures/ubuntu-18.04/ls-lR-newlines.out create mode 100644 tests/fixtures/ubuntu-18.04/ls-newlines.json create mode 100644 tests/fixtures/ubuntu-18.04/ls-newlines.out diff --git a/tests/fixtures/centos-7.7/ls-R-newlines.json b/tests/fixtures/centos-7.7/ls-R-newlines.json new file mode 100644 index 00000000..ba296353 --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-R-newlines.json @@ -0,0 +1 @@ +[{"filename": "systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u", "parent": "."}, {"filename": "systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv", "parent": "."}, {"filename": "systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j", "parent": "."}, {"filename": "tmp.CvALl2jE6u", "parent": "."}, {"filename": "tmp.e7AlxSxY5a", "parent": "."}, {"filename": "tmp.uXm9yegjwj", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}] diff --git a/tests/fixtures/centos-7.7/ls-R-newlines.out b/tests/fixtures/centos-7.7/ls-R-newlines.out new file mode 100644 index 00000000..6aa7d725 --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-R-newlines.out @@ -0,0 +1,43 @@ +.: +lstest +systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u +systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv +systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j +tmp.CvALl2jE6u +tmp.e7AlxSxY5a +tmp.uXm9yegjwj + +./lstest: +a regular filename + + +this file has +a combination + + +of everything + + + + +this file has +a newline inside +this file has + + + +four contiguous newlines inside +this file +has +six + +newlines + +within + + + + +this file starts with four newlines + +this file starts with one newline diff --git a/tests/fixtures/centos-7.7/ls-l-newlines.json b/tests/fixtures/centos-7.7/ls-l-newlines.json new file mode 100644 index 00000000..2ffaaf1f --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-l-newlines.json @@ -0,0 +1 @@ +[{"filename": "a regular filename", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:12"}, {"filename": "\n\nthis file has\na combination\n\n\nof everything\n\n\n\n", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:17"}, {"filename": "this file has\na newline inside", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:14"}, {"filename": "this file has\n\n\n\nfour contiguous newlines inside", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:14"}, {"filename": "this file\nhas\nsix\n\nnewlines\n\nwithin", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:16"}, {"filename": "\n\n\n\nthis file starts with four newlines", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:40"}, {"filename": "\nthis file starts with one newline", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:13"}] diff --git a/tests/fixtures/centos-7.7/ls-l-newlines.out b/tests/fixtures/centos-7.7/ls-l-newlines.out new file mode 100644 index 00000000..ede54970 --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-l-newlines.out @@ -0,0 +1,34 @@ +total 0 +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:12 a regular filename +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:17 + +this file has +a combination + + +of everything + + + + +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:14 this file has +a newline inside +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:14 this file has + + + +four contiguous newlines inside +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:16 this file +has +six + +newlines + +within +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:40 + + + +this file starts with four newlines +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:13 +this file starts with one newline diff --git a/tests/fixtures/centos-7.7/ls-lR-newlines.json b/tests/fixtures/centos-7.7/ls-lR-newlines.json new file mode 100644 index 00000000..e6d9bae8 --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-lR-newlines.json @@ -0,0 +1 @@ +[{"filename": "lstest", "parent": ".", "flags": "drwxrwxr-x.", "links": 2, "owner": "kbrazil", "group": "kbrazil", "size": 4096, "date": "Feb 22 00:40"}, {"filename": "systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u", "parent": ".", "flags": "drwx------.", "links": 3, "owner": "root", "group": "root", "size": 17, "date": "Feb 13 16:44"}, {"filename": "systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv", "parent": ".", "flags": "drwx------.", "links": 3, "owner": "root", "group": "root", "size": 17, "date": "Feb 17 17:48"}, {"filename": "systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j", "parent": ".", "flags": "drwx------.", "links": 3, "owner": "root", "group": "root", "size": 17, "date": "Feb 20 14:41"}, {"filename": "tmp.CvALl2jE6u", "parent": ".", "flags": "drwx------.", "links": 2, "owner": "root", "group": "root", "size": 6, "date": "Feb 13 16:44"}, {"filename": "tmp.e7AlxSxY5a", "parent": ".", "flags": "drwx------.", "links": 2, "owner": "root", "group": "root", "size": 6, "date": "Feb 20 14:41"}, {"filename": "tmp.uXm9yegjwj", "parent": ".", "flags": "drwx------.", "links": 2, "owner": "root", "group": "root", "size": 6, "date": "Feb 17 17:48"}, {"filename": "a regular filename", "parent": "./lstest", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:12"}, {"filename": "\n\nthis file has\na combination\n\n\nof everything\n\n\n\n", "parent": "./lstest", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:17"}, {"filename": "this file has\na newline inside", "parent": "./lstest", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:14"}, {"filename": "this file has\n\n\n\nfour contiguous newlines inside", "parent": "./lstest", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:14"}, {"filename": "this file\nhas\nsix\n\nnewlines\n\nwithin", "parent": "./lstest", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:16"}, {"filename": "\n\n\n\nthis file starts with four newlines", "parent": "./lstest", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:40"}, {"filename": "\nthis file starts with one newline", "parent": "./lstest", "flags": "-rw-rw-r--.", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 22 00:13"}] diff --git a/tests/fixtures/centos-7.7/ls-lR-newlines.out b/tests/fixtures/centos-7.7/ls-lR-newlines.out new file mode 100644 index 00000000..f23a2d5a --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-lR-newlines.out @@ -0,0 +1,45 @@ +.: +total 4 +drwxrwxr-x. 2 kbrazil kbrazil 4096 Feb 22 00:40 lstest +drwx------. 3 root root 17 Feb 13 16:44 systemd-private-016de60725a3426792b93fc9f120b8f0-chronyd.service-oZqq4u +drwx------. 3 root root 17 Feb 17 17:48 systemd-private-a30a5a178daa4042b42dfaf5ff9e5f68-chronyd.service-a1tpxv +drwx------. 3 root root 17 Feb 20 14:41 systemd-private-af69d7360f3e40cfa947358c0fb5a6f8-chronyd.service-T3MQ4j +drwx------. 2 root root 6 Feb 13 16:44 tmp.CvALl2jE6u +drwx------. 2 root root 6 Feb 20 14:41 tmp.e7AlxSxY5a +drwx------. 2 root root 6 Feb 17 17:48 tmp.uXm9yegjwj + +./lstest: +total 0 +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:12 a regular filename +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:17 + +this file has +a combination + + +of everything + + + + +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:14 this file has +a newline inside +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:14 this file has + + + +four contiguous newlines inside +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:16 this file +has +six + +newlines + +within +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:40 + + + +this file starts with four newlines +-rw-rw-r--. 1 kbrazil kbrazil 0 Feb 22 00:13 +this file starts with one newline diff --git a/tests/fixtures/centos-7.7/ls-newlines.json b/tests/fixtures/centos-7.7/ls-newlines.json new file mode 100644 index 00000000..ae6e7444 --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-newlines.json @@ -0,0 +1 @@ +[{"filename": "a regular filename"}, {"filename": "this file has"}, {"filename": "a combination"}, {"filename": "of everything"}, {"filename": "this file has"}, {"filename": "a newline inside"}, {"filename": "this file has"}, {"filename": "four contiguous newlines inside"}, {"filename": "this file"}, {"filename": "has"}, {"filename": "six"}, {"filename": "newlines"}, {"filename": "within"}, {"filename": "this file starts with four newlines"}, {"filename": "this file starts with one newline"}] diff --git a/tests/fixtures/centos-7.7/ls-newlines.out b/tests/fixtures/centos-7.7/ls-newlines.out new file mode 100644 index 00000000..2c9144f4 --- /dev/null +++ b/tests/fixtures/centos-7.7/ls-newlines.out @@ -0,0 +1,33 @@ +a regular filename + + +this file has +a combination + + +of everything + + + + +this file has +a newline inside +this file has + + + +four contiguous newlines inside +this file +has +six + +newlines + +within + + + + +this file starts with four newlines + +this file starts with one newline diff --git a/tests/fixtures/create_fixtures.sh b/tests/fixtures/create_fixtures.sh index c00f848f..5fe34569 100644 --- a/tests/fixtures/create_fixtures.sh +++ b/tests/fixtures/create_fixtures.sh @@ -40,6 +40,21 @@ ls -R /usr > ls-R.out ls -alR /usr > ls-alR.out ls /usr/* > ls-glob.out +cd /tmp/lstest +touch 'a regular filename' +touch $'\nthis file starts with one newline' +touch $'\n\n\n\nthis file starts with four newlines' +touch $'this file has\na newline inside' +touch $'this file has\n\n\n\nfour contiguous newlines inside' +touch $'this file\nhas\nsix\n\nnewlines\n\nwithin' +touch $'\n\nthis file has\na combination\n\n\nof everything\n\n\n\n' +cd /tmp +ls -R > ~/utils/ls-R-newlines.out +ls -lR > ~/utils/ls-lR-newlines.out +cd lstest +ls > ~/utils/ls-newlines.out +ls -l > ~/utils/ls-l-newlines.out + lsblk > lsblk.out lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR > lsblk-allcols.out lsmod > lsmod.out diff --git a/tests/fixtures/osx-10.14.6/ls-R-newlines.json b/tests/fixtures/osx-10.14.6/ls-R-newlines.json new file mode 100644 index 00000000..53ecef59 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-R-newlines.json @@ -0,0 +1 @@ +[{"filename": "lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}] diff --git a/tests/fixtures/osx-10.14.6/ls-R-newlines.out b/tests/fixtures/osx-10.14.6/ls-R-newlines.out new file mode 100644 index 00000000..8fcf9c7c --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-R-newlines.out @@ -0,0 +1,36 @@ +lstest + +./lstest: + + + + +this file starts with four newlines + + +this file has +a combination + + +of everything + + + + + +this file starts with one newline +a regular filename +this file +has +six + +newlines + +within +this file has + + + +four contiguous newlines inside +this file has +a newline inside diff --git a/tests/fixtures/osx-10.14.6/ls-l-newlines.json b/tests/fixtures/osx-10.14.6/ls-l-newlines.json new file mode 100644 index 00000000..a3e47665 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-l-newlines.json @@ -0,0 +1 @@ +[{"filename": "\n\n\n\nthis file starts with four newlines", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "\n\nthis file has\na combination\n\n\nof everything\n\n\n\n", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "\nthis file starts with one newline", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "a regular filename", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "this file\nhas\nsix\n\nnewlines\n\nwithin", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "this file has\n\n\n\nfour contiguous newlines inside", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "this file has\na newline inside", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}] diff --git a/tests/fixtures/osx-10.14.6/ls-l-newlines.out b/tests/fixtures/osx-10.14.6/ls-l-newlines.out new file mode 100644 index 00000000..3c746c0f --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-l-newlines.out @@ -0,0 +1,34 @@ +total 0 +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 + + + +this file starts with four newlines +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 + +this file has +a combination + + +of everything + + + + +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 +this file starts with one newline +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 a regular filename +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 this file +has +six + +newlines + +within +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 this file has + + + +four contiguous newlines inside +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 this file has +a newline inside diff --git a/tests/fixtures/osx-10.14.6/ls-lR-newlines.json b/tests/fixtures/osx-10.14.6/ls-lR-newlines.json new file mode 100644 index 00000000..0eff6e78 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-lR-newlines.json @@ -0,0 +1 @@ +[{"filename": "lstest", "flags": "drwxr-xr-x", "links": 9, "owner": "kbrazil", "group": "staff", "size": 288, "date": "Feb 27 10:19"}, {"filename": "\n\n\n\nthis file starts with four newlines", "parent": "./lstest", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "\n\nthis file has\na combination\n\n\nof everything\n\n\n\n", "parent": "./lstest", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "\nthis file starts with one newline", "parent": "./lstest", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "a regular filename", "parent": "./lstest", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "this file\nhas\nsix\n\nnewlines\n\nwithin", "parent": "./lstest", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "this file has\n\n\n\nfour contiguous newlines inside", "parent": "./lstest", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}, {"filename": "this file has\na newline inside", "parent": "./lstest", "flags": "-rw-r--r--", "links": 1, "owner": "kbrazil", "group": "staff", "size": 0, "date": "Feb 27 10:19"}] diff --git a/tests/fixtures/osx-10.14.6/ls-lR-newlines.out b/tests/fixtures/osx-10.14.6/ls-lR-newlines.out new file mode 100644 index 00000000..629026e1 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-lR-newlines.out @@ -0,0 +1,38 @@ +total 0 +drwxr-xr-x 9 kbrazil staff 288 Feb 27 10:19 lstest + +./lstest: +total 0 +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 + + + +this file starts with four newlines +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 + +this file has +a combination + + +of everything + + + + +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 +this file starts with one newline +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 a regular filename +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 this file +has +six + +newlines + +within +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 this file has + + + +four contiguous newlines inside +-rw-r--r-- 1 kbrazil staff 0 Feb 27 10:19 this file has +a newline inside diff --git a/tests/fixtures/osx-10.14.6/ls-newlines.json b/tests/fixtures/osx-10.14.6/ls-newlines.json new file mode 100644 index 00000000..60fde242 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/ls-newlines.json @@ -0,0 +1 @@ +[{"filename": "this file starts with four newlines"}, {"filename": "this file has"}, {"filename": "a combination"}, {"filename": "of everything"}, {"filename": "this file starts with one newline"}, {"filename": "a regular filename"}, {"filename": "this file"}, {"filename": "has"}, {"filename": "six"}, {"filename": "newlines"}, {"filename": "within"}, {"filename": "this file has"}, {"filename": "four contiguous newlines inside"}, {"filename": "this file has"}, {"filename": "a newline inside"}] diff --git a/tests/fixtures/osx-10.14.6/ls-newlines.out b/tests/fixtures/osx-10.14.6/ls-newlines.out index a792207e..46ff8cf0 100644 --- a/tests/fixtures/osx-10.14.6/ls-newlines.out +++ b/tests/fixtures/osx-10.14.6/ls-newlines.out @@ -1,151 +1,33 @@ -total 584 --rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:55 -three newlines start this file -drwxr-xr-x 3 root wheel 96 Feb 24 12:13 MacAgent --rw------- 1 root wheel 0 Feb 24 16:33 _Library_Application Support_Fortinet_FortiClient_data__vir_high --rw------- 1 root wheel 0 Feb 24 16:33 _Library_Application Support_Fortinet_FortiClient_tmp_avsig_delata_vir_high -srwxr-xr-x 1 kbrazil wheel 0 Feb 20 14:41 centosserial --rw-r--r-- 1 root wheel 382 Feb 20 14:41 centosserial.sh.log -drwx------ 3 kbrazil wheel 96 Feb 7 23:32 com.apple.launchd.ZRwqedKmO9 -drwx------ 3 kbrazil wheel 96 Feb 7 23:32 com.apple.launchd.xPCDEP69Cl -srwxrwxrwx 1 kbrazil wheel 0 Feb 7 23:32 fctvpnctl.sock -srw------- 1 kbrazil wheel 0 Feb 7 23:32 fctvpnctl.sock_501 --rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:58 ls-newlines.out -drwxr-xr-x 10 kbrazil wheel 320 Feb 24 16:58 lstest -srw-rw-rw- 1 root wheel 0 Feb 7 23:31 olisne-WY4G9IZafUNsloCollectorServicePipe --rwx------ 1 root wheel 535 Feb 22 18:56 scriptcode.0JeYTA --rwx------ 1 root wheel 531 Feb 22 19:19 scriptcode.0d9OX9 --rwx------ 1 root wheel 535 Feb 24 12:12 scriptcode.0jvSGh --rwx------ 1 root wheel 3312 Feb 20 17:43 scriptcode.26L6Aw --rwx------ 1 root wheel 311 Feb 22 18:56 scriptcode.2KJ0DB --rwx------ 1 root wheel 316 Feb 21 18:10 scriptcode.3iQbCH --rwx------ 1 root wheel 1068 Feb 21 18:10 scriptcode.47tsJK --rwx------ 1 root wheel 316 Feb 24 12:12 scriptcode.5EGutx --rwx------ 1 root wheel 279 Feb 24 12:12 scriptcode.73zg3m --rwx------ 1 root wheel 920 Feb 22 19:19 scriptcode.7EKhVr --rwx------ 1 root wheel 408 Feb 22 19:19 scriptcode.7XsHV0 --rwx------ 1 root wheel 531 Feb 20 17:43 scriptcode.7lVOvs --rwx------ 1 root wheel 1068 Feb 20 17:43 scriptcode.AHABAG --rwx------ 1 root wheel 316 Feb 20 17:43 scriptcode.CnQHRy --rwx------ 1 root wheel 279 Feb 21 18:41 scriptcode.FEStzN --rwx------ 1 root wheel 277 Feb 20 17:43 scriptcode.FY7cUj --rwx------ 1 root wheel 1292 Feb 20 17:43 scriptcode.GY4L8Z --rwx------ 1 root wheel 535 Feb 20 17:05 scriptcode.Gz2pae --rwx------ 1 root wheel 311 Feb 21 18:09 scriptcode.GzIQzf --rwx------ 1 root wheel 920 Feb 24 12:12 scriptcode.HPloGp --rwx------ 1 root wheel 531 Feb 24 12:12 scriptcode.HtJdie --rwx------ 1 root wheel 311 Feb 24 12:11 scriptcode.Ihm1Oo --rwx------ 1 root wheel 277 Feb 22 19:19 scriptcode.IkV9ka --rwx------ 1 root wheel 3312 Feb 24 12:12 scriptcode.KKN22F --rwx------ 1 root wheel 279 Feb 24 12:12 scriptcode.Kx84Te --rwx------ 1 root wheel 408 Feb 24 12:12 scriptcode.LyuE2u --rwx------ 1 root wheel 400 Feb 21 18:41 scriptcode.N2AhIg --rwx------ 1 root wheel 1208 Feb 24 12:12 scriptcode.Nqmmg7 --rwx------ 1 root wheel 3312 Feb 21 18:10 scriptcode.OHRPTO --rwx------ 1 root wheel 277 Feb 24 12:12 scriptcode.OQCX7n --rwx------ 1 root wheel 535 Feb 21 18:41 scriptcode.PoKNUA --rwx------ 1 root wheel 531 Feb 22 19:19 scriptcode.R2XvfH --rwx------ 1 root wheel 408 Feb 21 18:10 scriptcode.R4JK3n --rwx------ 1 root wheel 1292 Feb 21 18:41 scriptcode.RgJYtc --rwx------ 1 root wheel 531 Feb 20 17:43 scriptcode.SeUnOY --rwx------ 1 root wheel 316 Feb 22 19:19 scriptcode.SmpfaH --rwx------ 1 root wheel 1208 Feb 21 18:41 scriptcode.Sqk4gn --rwx------ 1 root wheel 311 Feb 21 18:09 scriptcode.SxoG8F --rwx------ 1 root wheel 531 Feb 24 12:12 scriptcode.ThENy0 --rwx------ 1 root wheel 311 Feb 22 18:56 scriptcode.TjBafP --rwx------ 1 root wheel 279 Feb 20 17:43 scriptcode.VYNiW2 --rwx------ 1 root wheel 535 Feb 24 12:11 scriptcode.Yyqf85 --rwx------ 1 root wheel 535 Feb 22 19:19 scriptcode.aVTtu2 --rwx------ 1 root wheel 1208 Feb 20 17:43 scriptcode.czs9l6 --rwx------ 1 root wheel 920 Feb 20 17:43 scriptcode.eFVE3D --rwx------ 1 root wheel 1292 Feb 24 12:12 scriptcode.f88eGZ --rwx------ 1 root wheel 282 Feb 24 12:12 scriptcode.flB4nR --rwx------ 1 root wheel 277 Feb 21 18:41 scriptcode.iMzN8Y --rwx------ 1 root wheel 535 Feb 20 17:43 scriptcode.iPaXLd --rwx------ 1 root wheel 279 Feb 21 18:41 scriptcode.jkaeC8 --rwx------ 1 root wheel 1292 Feb 22 19:19 scriptcode.k0Qc64 --rwx------ 1 root wheel 279 Feb 20 17:43 scriptcode.kH4nP3 --rwx------ 1 root wheel 282 Feb 20 17:43 scriptcode.l0Wcmj --rwx------ 1 root wheel 311 Feb 24 12:11 scriptcode.lWzSJu --rwx------ 1 root wheel 279 Feb 22 19:19 scriptcode.m1wgPP --rwx------ 1 root wheel 1208 Feb 22 19:19 scriptcode.mG7NEw --rwx------ 1 root wheel 531 Feb 21 18:41 scriptcode.mfGENQ --rwx------ 1 root wheel 1068 Feb 24 12:12 scriptcode.n4urXg --rwx------ 1 root wheel 535 Feb 21 18:09 scriptcode.n5Hn9m --rwx------ 1 root wheel 282 Feb 21 18:10 scriptcode.nggGXs --rwx------ 1 root wheel 400 Feb 24 12:12 scriptcode.obdjU7 --rwx------ 1 root wheel 1068 Feb 22 19:19 scriptcode.pIBQku --rwx------ 1 root wheel 400 Feb 22 19:19 scriptcode.pmiMa5 --rwx------ 1 root wheel 400 Feb 20 17:43 scriptcode.qd2MtX --rwx------ 1 root wheel 311 Feb 20 17:05 scriptcode.sF2VTO --rwx------ 1 root wheel 920 Feb 21 18:41 scriptcode.sWaDJU --rwx------ 1 root wheel 408 Feb 20 17:43 scriptcode.tb9thN --rwx------ 1 root wheel 3312 Feb 22 19:19 scriptcode.v5rHnt --rwx------ 1 root wheel 531 Feb 21 18:41 scriptcode.xSmYzD --rwx------ 1 root wheel 311 Feb 20 17:05 scriptcode.xztElJ --rwx------ 1 root wheel 282 Feb 22 19:19 scriptcode.z1R5gD --rwx------ 1 root wheel 279 Feb 22 19:19 scriptcode.zPNZQP -drwx------ 3 kbrazil wheel 96 Feb 13 16:44 vmware-kbrazil - -./MacAgent: -total 416 --rw-r--r-- 1 root wheel 211848 Feb 24 12:13 vulscanOut.xml - -./com.apple.launchd.ZRwqedKmO9: -total 0 -srw-rw-rw- 1 kbrazil wheel 0 Feb 7 23:32 Render - -./com.apple.launchd.xPCDEP69Cl: -total 0 -srw-rw-rw- 1 kbrazil wheel 0 Feb 7 23:32 Listeners - -./lstest: -total 0 --rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:58 -combo of +this file starts with four newlines + + +this file has +a combination + + +of everything + + + + + +this file starts with one newline +a regular filename +this file +has +six + newlines -inside -and trailing - -this file +within +this file has - - - --rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:55 - - -three newlines start this file --rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:42 -this file has a newline in the beginning --rw-r--r-- 1 kbrazil wheel 0 Feb 24 14:56 another filename with -multiple -newline characters --rw-r--r-- 1 kbrazil wheel 0 Feb 24 16:35 filename with - -two newlines and two trailing newlines - - --rw-r--r-- 1 kbrazil wheel 0 Feb 24 14:55 filename with a -newline character --rw-r--r-- 1 kbrazil wheel 0 Feb 24 14:56 regularfile --rw-r--r-- 1 kbrazil wheel 0 Feb 24 15:44 this filename has - - - -four newlines in it - -./vmware-kbrazil: -total 0 -drwx------ 3 kbrazil wheel 96 Feb 20 14:41 mksctrl - -./vmware-kbrazil/mksctrl: -total 0 -srwxr-xr-x 1 kbrazil wheel 0 Feb 20 14:41 mksctrl-0000002818-000-39aec79d +four contiguous newlines inside +this file has +a newline inside diff --git a/tests/fixtures/ubuntu-18.04/ls-R-newlines.json b/tests/fixtures/ubuntu-18.04/ls-R-newlines.json new file mode 100644 index 00000000..bc2fa382 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-R-newlines.json @@ -0,0 +1 @@ +[{"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-resolved.service-La9AqY", "parent": "."}, {"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-timesyncd.service-L7q4cJ", "parent": "."}, {"filename": "vmware-root_670-2722828838", "parent": "."}, {"filename": "a regular filename", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a combination", "parent": "./lstest"}, {"filename": "of everything", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "a newline inside", "parent": "./lstest"}, {"filename": "this file has", "parent": "./lstest"}, {"filename": "four contiguous newlines inside", "parent": "./lstest"}, {"filename": "this file", "parent": "./lstest"}, {"filename": "has", "parent": "./lstest"}, {"filename": "six", "parent": "./lstest"}, {"filename": "newlines", "parent": "./lstest"}, {"filename": "within", "parent": "./lstest"}, {"filename": "this file starts with four newlines", "parent": "./lstest"}, {"filename": "this file starts with one newline", "parent": "./lstest"}] diff --git a/tests/fixtures/ubuntu-18.04/ls-R-newlines.out b/tests/fixtures/ubuntu-18.04/ls-R-newlines.out new file mode 100644 index 00000000..79f71b20 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-R-newlines.out @@ -0,0 +1,40 @@ +.: +lstest +systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-resolved.service-La9AqY +systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-timesyncd.service-L7q4cJ +vmware-root_670-2722828838 + +./lstest: +a regular filename + + +this file has +a combination + + +of everything + + + + +this file has +a newline inside +this file has + + + +four contiguous newlines inside +this file +has +six + +newlines + +within + + + + +this file starts with four newlines + +this file starts with one newline diff --git a/tests/fixtures/ubuntu-18.04/ls-l-newlines.json b/tests/fixtures/ubuntu-18.04/ls-l-newlines.json new file mode 100644 index 00000000..1f77a568 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-l-newlines.json @@ -0,0 +1 @@ +[{"filename": "a regular filename", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "\n\nthis file has\na combination\n\n\nof everything\n\n\n\n", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "this file has\na newline inside", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "this file has\n\n\n\nfour contiguous newlines inside", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "this file\nhas\nsix\n\nnewlines\n\nwithin", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "\n\n\n\nthis file starts with four newlines", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "\nthis file starts with one newline", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}] diff --git a/tests/fixtures/ubuntu-18.04/ls-l-newlines.out b/tests/fixtures/ubuntu-18.04/ls-l-newlines.out new file mode 100644 index 00000000..1fb98bba --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-l-newlines.out @@ -0,0 +1,34 @@ +total 0 +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 a regular filename +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 + +this file has +a combination + + +of everything + + + + +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 this file has +a newline inside +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 this file has + + + +four contiguous newlines inside +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 this file +has +six + +newlines + +within +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 + + + +this file starts with four newlines +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 +this file starts with one newline diff --git a/tests/fixtures/ubuntu-18.04/ls-lR-newlines.json b/tests/fixtures/ubuntu-18.04/ls-lR-newlines.json new file mode 100644 index 00000000..341999c8 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-lR-newlines.json @@ -0,0 +1 @@ +[{"filename": "lstest", "parent": ".", "flags": "drwxrwxr-x", "links": 2, "owner": "kbrazil", "group": "kbrazil", "size": 4096, "date": "Feb 27 18:08"}, {"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-resolved.service-La9AqY", "parent": ".", "flags": "drwx------", "links": 3, "owner": "root", "group": "root", "size": 4096, "date": "Feb 27 18:07"}, {"filename": "systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-timesyncd.service-L7q4cJ", "parent": ".", "flags": "drwx------", "links": 3, "owner": "root", "group": "root", "size": 4096, "date": "Feb 27 18:07"}, {"filename": "vmware-root_670-2722828838", "parent": ".", "flags": "drwx------", "links": 2, "owner": "root", "group": "root", "size": 4096, "date": "Feb 27 18:07"}, {"filename": "a regular filename", "parent": "./lstest", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "\n\nthis file has\na combination\n\n\nof everything\n\n\n\n", "parent": "./lstest", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "this file has\na newline inside", "parent": "./lstest", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "this file has\n\n\n\nfour contiguous newlines inside", "parent": "./lstest", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "this file\nhas\nsix\n\nnewlines\n\nwithin", "parent": "./lstest", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "\n\n\n\nthis file starts with four newlines", "parent": "./lstest", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}, {"filename": "\nthis file starts with one newline", "parent": "./lstest", "flags": "-rw-rw-r--", "links": 1, "owner": "kbrazil", "group": "kbrazil", "size": 0, "date": "Feb 27 18:08"}] diff --git a/tests/fixtures/ubuntu-18.04/ls-lR-newlines.out b/tests/fixtures/ubuntu-18.04/ls-lR-newlines.out new file mode 100644 index 00000000..2a8c1f1c --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-lR-newlines.out @@ -0,0 +1,42 @@ +.: +total 16 +drwxrwxr-x 2 kbrazil kbrazil 4096 Feb 27 18:08 lstest +drwx------ 3 root root 4096 Feb 27 18:07 systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-resolved.service-La9AqY +drwx------ 3 root root 4096 Feb 27 18:07 systemd-private-65c1089f1d4c4cf5bc50ca55478abfde-systemd-timesyncd.service-L7q4cJ +drwx------ 2 root root 4096 Feb 27 18:07 vmware-root_670-2722828838 + +./lstest: +total 0 +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 a regular filename +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 + +this file has +a combination + + +of everything + + + + +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 this file has +a newline inside +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 this file has + + + +four contiguous newlines inside +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 this file +has +six + +newlines + +within +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 + + + +this file starts with four newlines +-rw-rw-r-- 1 kbrazil kbrazil 0 Feb 27 18:08 +this file starts with one newline diff --git a/tests/fixtures/ubuntu-18.04/ls-newlines.json b/tests/fixtures/ubuntu-18.04/ls-newlines.json new file mode 100644 index 00000000..ae6e7444 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-newlines.json @@ -0,0 +1 @@ +[{"filename": "a regular filename"}, {"filename": "this file has"}, {"filename": "a combination"}, {"filename": "of everything"}, {"filename": "this file has"}, {"filename": "a newline inside"}, {"filename": "this file has"}, {"filename": "four contiguous newlines inside"}, {"filename": "this file"}, {"filename": "has"}, {"filename": "six"}, {"filename": "newlines"}, {"filename": "within"}, {"filename": "this file starts with four newlines"}, {"filename": "this file starts with one newline"}] diff --git a/tests/fixtures/ubuntu-18.04/ls-newlines.out b/tests/fixtures/ubuntu-18.04/ls-newlines.out new file mode 100644 index 00000000..2c9144f4 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/ls-newlines.out @@ -0,0 +1,33 @@ +a regular filename + + +this file has +a combination + + +of everything + + + + +this file has +a newline inside +this file has + + + +four contiguous newlines inside +this file +has +six + +newlines + +within + + + + +this file starts with four newlines + +this file starts with one newline diff --git a/tests/test_ls.py b/tests/test_ls.py index 6e5ce00f..f4e454cb 100644 --- a/tests/test_ls.py +++ b/tests/test_ls.py @@ -73,6 +73,42 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-glob.out'), 'r') as f: self.osx_10_14_6_ls_glob = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-R-newlines.out'), 'r') as f: + self.centos_7_7_ls_R_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-R-newlines.out'), 'r') as f: + self.ubuntu_18_4_ls_R_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-R-newlines.out'), 'r') as f: + self.osx_10_14_6_ls_R_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-l-newlines.out'), 'r') as f: + self.centos_7_7_ls_l_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-l-newlines.out'), 'r') as f: + self.ubuntu_18_4_ls_l_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-l-newlines.out'), 'r') as f: + self.osx_10_14_6_ls_l_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-lR-newlines.out'), 'r') as f: + self.centos_7_7_ls_lR_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-lR-newlines.out'), 'r') as f: + self.ubuntu_18_4_ls_lR_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-lR-newlines.out'), 'r') as f: + self.osx_10_14_6_ls_lR_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-newlines.out'), 'r') as f: + self.centos_7_7_ls_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-newlines.out'), 'r') as f: + self.ubuntu_18_4_ls_newlines = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-newlines.out'), 'r') as f: + self.osx_10_14_6_ls_newlines = f.read() + # output with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls.json'), 'r') as f: self.centos_7_7_ls_json = json.loads(f.read()) @@ -137,6 +173,42 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-glob.json'), 'r') as f: self.osx_10_14_6_ls_glob_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-R-newlines.json'), 'r') as f: + self.centos_7_7_ls_R_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-R-newlines.json'), 'r') as f: + self.ubuntu_18_4_ls_R_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-R-newlines.json'), 'r') as f: + self.osx_10_14_6_ls_R_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-l-newlines.json'), 'r') as f: + self.centos_7_7_ls_l_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-l-newlines.json'), 'r') as f: + self.ubuntu_18_4_ls_l_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-l-newlines.json'), 'r') as f: + self.osx_10_14_6_ls_l_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-lR-newlines.json'), 'r') as f: + self.centos_7_7_ls_lR_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-lR-newlines.json'), 'r') as f: + self.ubuntu_18_4_ls_lR_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-lR-newlines.json'), 'r') as f: + self.osx_10_14_6_ls_lR_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ls-newlines.json'), 'r') as f: + self.centos_7_7_ls_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ls-newlines.json'), 'r') as f: + self.ubuntu_18_4_ls_newlines_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ls-newlines.json'), 'r') as f: + self.osx_10_14_6_ls_newlines_json = json.loads(f.read()) + def test_ls_centos_7_7(self): """ Test plain 'ls /' on Centos 7.7 @@ -263,6 +335,78 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.ls.parse(self.osx_10_14_6_ls_glob, quiet=True), self.osx_10_14_6_ls_glob_json) + def test_ls_R_newlines_centos_7_7(self): + """ + Test 'ls -R' for filenames with newline characters on Centos 7.7 + """ + self.assertEqual(jc.parsers.ls.parse(self.centos_7_7_ls_R_newlines, quiet=True), self.centos_7_7_ls_R_newlines_json) + + def test_ls_R_newlines_ubuntu_18_4(self): + """ + Test 'ls -R' for filenames with newline characters on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.ls.parse(self.ubuntu_18_4_ls_R_newlines, quiet=True), self.ubuntu_18_4_ls_R_newlines_json) + + def test_ls_R_newlines_osx_10_14_6(self): + """ + Test 'ls -R' for filenames with newline characters on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.ls.parse(self.osx_10_14_6_ls_R_newlines, quiet=True), self.osx_10_14_6_ls_R_newlines_json) + + def test_ls_l_newlines_centos_7_7(self): + """ + Test 'ls -l' for filenames with newline characters on Centos 7.7 + """ + self.assertEqual(jc.parsers.ls.parse(self.centos_7_7_ls_l_newlines, quiet=True), self.centos_7_7_ls_l_newlines_json) + + def test_ls_l_newlines_ubuntu_18_4(self): + """ + Test 'ls -l' for filenames with newline characters on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.ls.parse(self.ubuntu_18_4_ls_l_newlines, quiet=True), self.ubuntu_18_4_ls_l_newlines_json) + + def test_ls_l_newlines_osx_10_14_6(self): + """ + Test 'ls -l' for filenames with newline characters on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.ls.parse(self.osx_10_14_6_ls_l_newlines, quiet=True), self.osx_10_14_6_ls_l_newlines_json) + + def test_ls_lR_newlines_centos_7_7(self): + """ + Test 'ls -lR' for filenames with newline characters on Centos 7.7 + """ + self.assertEqual(jc.parsers.ls.parse(self.centos_7_7_ls_lR_newlines, quiet=True), self.centos_7_7_ls_lR_newlines_json) + + def test_ls_lR_newlines_ubuntu_18_4(self): + """ + Test 'ls -lR' for filenames with newline characters on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.ls.parse(self.ubuntu_18_4_ls_lR_newlines, quiet=True), self.ubuntu_18_4_ls_lR_newlines_json) + + def test_ls_lR_newlines_osx_10_14_6(self): + """ + Test 'ls -lR' for filenames with newline characters on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.ls.parse(self.osx_10_14_6_ls_lR_newlines, quiet=True), self.osx_10_14_6_ls_lR_newlines_json) + + def test_ls_newlines_centos_7_7(self): + """ + Test 'ls' for filenames with newline characters on Centos 7.7 + """ + self.assertEqual(jc.parsers.ls.parse(self.centos_7_7_ls_newlines, quiet=True), self.centos_7_7_ls_newlines_json) + + def test_ls_newlines_ubuntu_18_4(self): + """ + Test 'ls' for filenames with newline characters on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.ls.parse(self.ubuntu_18_4_ls_newlines, quiet=True), self.ubuntu_18_4_ls_newlines_json) + + def test_ls_newlines_osx_10_14_6(self): + """ + Test 'ls' for filenames with newline characters on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.ls.parse(self.osx_10_14_6_ls_newlines, quiet=True), self.osx_10_14_6_ls_newlines_json) + if __name__ == '__main__': unittest.main() From 8bfa0bddec9ff1c21972019467dcf5738ab3afd2 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 27 Feb 2020 10:50:05 -0800 Subject: [PATCH 13/13] version bump to 1.7.5 --- changelog.txt | 3 +++ jc/cli.py | 2 +- setup.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index b2bb6335..662159b0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ jc changelog +20200227 v1.7.5 +- Updated ls parser to support filenames with newline characters + 20200219 v1.7.4 - Updated ls parser to support multiple directories, globbing, and -R (recursive) diff --git a/jc/cli.py b/jc/cli.py index ed90b6f7..0d5b8eaa 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -13,7 +13,7 @@ import jc.utils class info(): - version = '1.7.4' + version = '1.7.5' description = 'jc cli output JSON conversion tool' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' diff --git a/setup.py b/setup.py index 52243f83..62d38a27 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.7.4', + version='1.7.5', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='This tool serializes the output of popular command line tools and filetypes to structured JSON output.',