Appending to a nested array causes an exception in pyparsing due to wrong type
pyparsing.lineno expects the second parameter to be a string.
However, in 2 locations within config_parser.py (here, and here), you set the instring parameter for a ConfigSubstitution to a boolean instead of a string, causing pyhocon to crash (instead of giving the expected error message) in cases where the key cannot be resolved.
Example:
foo: {bar: []}
foo.bar += []
And code:
import sys
from pyhocon import ConfigFactory
input = sys.stdin.read()
config = ConfigFactory.parse_string(input)
Causes:
Traceback (most recent call last):
File "test.py", line 6, in <module>
config = ConfigFactory.parse_string(input)
File "<redacted>/pyhocon/config_parser.py", line 90, in parse_string
return ConfigParser().parse(content, basedir, resolve)
File "<redacted>/pyhocon/config_parser.py", line 275, in parse
ConfigParser.resolve_substitutions(config)
File "<redacted>/pyhocon/config_parser.py", line 446, in resolve_substitutions
col=col(substitution.loc, substitution.instring)) for substitution in substitutions)))
File "<redacted>/pyhocon/config_parser.py", line 446, in <genexpr>
col=col(substitution.loc, substitution.instring)) for substitution in substitutions)))
File "<redacted>/env/lib/python2.7/site-packages/pyparsing.py", line 968, in lineno
return strg.count("\n",0,loc) + 1
AttributeError: 'bool' object has no attribute 'count'
_Aside_ Further, I'm not sure that this should be raising an exception anyway. For example:
a = []
a += []
is allowed in the HOCON spec.
It seems to me that pyhocon should be able to resolve foo.bar. However that is another issue (possibly #97), and fixing this issue will at least make the code consistent with this case (which the HOCON spec says is equivalent):
foo: {bar: []}
foo.bar = ${?foo.bar} []
A shout out to American Fuzzy Lop which helped me find these issues.
@sanzinger, this is your code. Perhaps you could help out with this one?
i was trying to scan a play config file with below values in it:
play.filters.disabled+=play.filters.csrf.CSRFFilter
play.filters.disabled+=play.filters.headers.SecurityHeadersFilter
play.filters.disabled+=play.filters.hosts.AllowedHostsFilter
I got the same error as above.
cat /tmp/application.conf| pyhocon -f properties
Traceback (most recent call last):
File "/usr/local/bin/pyhocon", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/pyhocon/tool.py", line 268, in main
HOCONConverter.convert_from_file(args.input, args.output, args.format.lower(), args.indent, args.compact)
File "/usr/local/lib/python3.6/site-packages/pyhocon/tool.py", line 233, in convert_from_file
config = ConfigFactory.parse_string(content)
File "/usr/local/lib/python3.6/site-packages/pyhocon/config_parser.py", line 94, in parse_string
return ConfigParser().parse(content, basedir, resolve)
File "/usr/local/lib/python3.6/site-packages/pyhocon/config_parser.py", line 293, in parse
ConfigParser.resolve_substitutions(config)
File "/usr/local/lib/python3.6/site-packages/pyhocon/config_parser.py", line 457, in resolve_substitutions
col=col(substitution.loc, substitution.instring)) for substitution in substitutions)))
File "/usr/local/lib/python3.6/site-packages/pyhocon/config_parser.py", line 457, in <genexpr>
col=col(substitution.loc, substitution.instring)) for substitution in substitutions)))
File "/usr/local/lib/python3.6/site-packages/pyparsing.py", line 968, in lineno
return strg.count("\n",0,loc) + 1
AttributeError: 'bool' object has no attribute 'count'
it looks like += is not being parsed correctly.