Repository: RedHatInsights/insights-core

Issue:
There is special characters in comment in httpd conf files
From one of the production insights archives, I found the following line in http conf file:
```
#Alterações realizadas por issue no Insights
```
then the parser raises the following exception
```
  File "/Users/huali/worktree/insights/insights-core/insights/combiners/httpd_conf.py", line 328, in __call__
    return self.Top(content)
  File "/Users/huali/worktree/insights/insights-core/insights/parsr/__init__.py", line 332, in __call__
    raise Exception(err.read())
Exception: At line 41 column 10:
```



Discussion:

Resolving patch:
diff --git a/insights/parsr/__init__.py b/insights/parsr/__init__.py
--- a/insights/parsr/__init__.py
+++ b/insights/parsr/__init__.py
@@ -335,6 +335,16 @@ def __repr__(self):
         return self.name or self.__class__.__name__
 
 
+class AnyChar(Parser):
+    def process(self, pos, data, ctx):
+        c = data[pos]
+        if c is not None:
+            return (pos + 1, c)
+        msg = "Expected any character."
+        ctx.set(pos, msg)
+        raise Exception(msg)
+
+
 class Char(Parser):
     """
     Char matches a single character.
@@ -1040,7 +1050,7 @@ class OneLineComment(Parser):
     """
     def __init__(self, s):
         super(OneLineComment, self).__init__()
-        p = Literal(s) >> Opt(String(set(string.printable) - set("\r\n")), "")
+        p = Literal(s) >> Opt(AnyChar.until(InSet("\r\n")), "")
         self.add_child(p)
 
     def process(self, pos, data, ctx):
@@ -1179,7 +1189,7 @@ def skip_none(x):
 Colon = Char(":")
 SemiColon = Char(";")
 Comma = Char(",")
-AnyChar = InSet(string.printable) % "Any Char"
+AnyChar = AnyChar()
 NonZeroDigit = InSet(set(string.digits) - set("0"))
 Digit = InSet(string.digits) % "Digit"
 Digits = String(string.digits) % "Digits"


Test patch:
diff --git a/insights/combiners/tests/test_httpd_conf_tree.py b/insights/combiners/tests/test_httpd_conf_tree.py
--- a/insights/combiners/tests/test_httpd_conf_tree.py
+++ b/insights/combiners/tests/test_httpd_conf_tree.py
@@ -1,3 +1,4 @@
+# coding=utf-8
 from insights.combiners.httpd_conf import (_HttpdConf, HttpdConfTree, _HttpdConfSclHttpd24,
     HttpdConfSclHttpd24Tree, _HttpdConfSclJbcsHttpd24, HttpdConfSclJbcsHttpd24Tree)
 from insights.tests import context_wrap
@@ -466,6 +467,14 @@
 """.strip()  # noqa W293
 
 
+UNICODE_COMMENTS = """
+#Alterações realizadas por issue no Insights
+DNSSDEnable on
+#DNSSDAutoRegisterVHosts on
+#DNSSDAutoRegisterUserDir on
+"""
+
+
 def test_mixed_case_tags():
     httpd = _HttpdConf(context_wrap(HTTPD_CONF_MIXED, path='/etc/httpd/conf/httpd.conf'))
     assert httpd.find("ServerLimit").value == 256
@@ -744,3 +753,11 @@ def test_regex_and_op_attrs():
 
     if_version = result["IfVersion"]
     assert len(if_version) == 1
+
+
+def test_unicode_comments():
+    httpd = _HttpdConf(context_wrap(UNICODE_COMMENTS, path='/etc/httpd/conf/httpd.conf'))
+    result = HttpdConfTree([httpd])
+
+    rewrite_cond = result["DNSSDEnable"]
+    assert len(rewrite_cond) == 1
diff --git a/insights/combiners/tests/test_logrotate_conf_tree.py b/insights/combiners/tests/test_logrotate_conf_tree.py
--- a/insights/combiners/tests/test_logrotate_conf_tree.py
+++ b/insights/combiners/tests/test_logrotate_conf_tree.py
@@ -1,3 +1,4 @@
+# coding=utf-8
 from insights.parsr.query import first
 from insights.combiners.logrotate_conf import _LogRotateConf, LogRotateConfTree
 from insights.tests import context_wrap
@@ -49,6 +50,22 @@
 """.strip()
 
 
+JUNK_SPACE = """
+#SEG_15.06.01 
+/var/log/spooler
+{
+    compress
+    missingok
+    rotate 30
+    size 1M
+    sharedscripts
+    postrotate
+        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
+    endscript
+}
+""".strip()
+
+
 def test_logrotate_tree():
     p = _LogRotateConf(context_wrap(CONF, path="/etc/logrotate.conf"))
     conf = LogRotateConfTree([p])
@@ -59,3 +76,9 @@ def test_logrotate_tree():
     assert len(conf["/var/log/btmp"]["rotate"]) == 1
     assert len(conf["/var/log/btmp"]["postrotate"]) == 1
     assert conf["/var/log/btmp"]["postrotate"][first].value == "do some stuff to btmp"
+
+
+def test_junk_space():
+    p = _LogRotateConf(context_wrap(JUNK_SPACE, path="/etc/logrotate.conf"))
+    conf = LogRotateConfTree([p])
+    assert "compress" in conf["/var/log/spooler"]