Kintyre / ksconf

Kintyre's Splunk Configuration tool
Apache License 2.0
50 stars 13 forks source link

ksconf merge fails with conf file with UTF-8 BOM #27

Closed lowell80 closed 5 years ago

lowell80 commented 6 years ago

Attempting to merge files written on a WIndows platform (CR/LF end-of-line) causes the merge to abort.

ksconf merge: error: argument FILE: failed to parse 'alert_logevent/local/indexes.conf': Dangling stanza header:  [service_manager_qa]

However, ksconf check of the same files says everything is fine. Weird:

$ ksconf check alert_logevent/local/indexes.conf
Successfully parsed alert_logevent/local/indexes.conf
Completed checking 1 files.  rc=0 Breakdown:
   1 files were parsed successfully.
   0 files failed.

No ability to change the parsing profile from the CLI (strictness).

ksconf 0.5.2 (Build 157) Python: 3.6.5 (/Users/lalleman/.pyenv/versions/3.6.5/bin/python3.6) Git SHA1 fda4eecc committed on 2018-08-12

lowell80 commented 6 years ago

This is BOM issue. BOM-UTF8. Most likely caused by parse_stream() vs parse_file(). Working on an alternative.

lowell80 commented 6 years ago

This needs a unit test!

lowell80 commented 5 years ago

Found another occurrence of this issue in 0.7.0 (230a0a7cf). The file command reports this as:

UTF-8 Unicode (with BOM) text

This happens for merge and sort. (Though, depending on the python version you get two different errors:

Python 2:

Unhandled top-level exception.  'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "/Users/lalleman/Sandbox/ksconf/ksconf/__main__.py", line 155, in cli
    return_code = args.funct(args)
  File "ksconf/commands/__init__.py", line 364, in launch
    return_code = self.run(args)
  File "ksconf/commands/sort.py", line 111, in run
    data = parse_conf(conf, profile=PARSECONF_STRICT)
  File "ksconf/conf/parser.py", line 234, in parse_conf
    return parse_conf_stream(stream, **profile)
  File "ksconf/conf/parser.py", line 256, in parse_conf_stream
    for section, entry in reader:
  File "ksconf/conf/parser.py", line 118, in section_reader
    line = line.rstrip("\r\n")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)

Or in Python 3:

Error trying processing MYAPP/local/app.conf.  Error:  Unexpected entry: