pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

Self-referential substitutions fail if key is a path

Open gilles-duboscq opened this issue 9 years ago • 2 comments

As reported in #35 these 2 examples fail:

a.b.c += "foo"
a.b.c = ${?a.b.c} ["foo"]

(to see the actual exceptions, this first patch is necessary:

diff --git a/pyhocon/config_parser.py b/pyhocon/config_parser.py
index 9e20236..f29869c 100644
--- a/pyhocon/config_parser.py
+++ b/pyhocon/config_parser.py
@@ -510,10 +510,10 @@ class ConfigTreeParser(TokenConverter):
                 else:
                     value = values[0]
                     if isinstance(value, list) and operator == "+=":
-                        value = ConfigValues([ConfigSubstitution(key, True, '', False, loc), value], False, loc)
+                        value = ConfigValues([ConfigSubstitution(key, True, '', instring, loc), value], False, loc)
                         config_tree.put(key, value, False)
                     elif isinstance(value, str) and operator == "+=":
-                        value = ConfigValues([ConfigSubstitution(key, True, '', True, loc), ' ' + value], True, loc)
+                        value = ConfigValues([ConfigSubstitution(key, True, '', instring, loc), ' ' + value], True, loc)
                         config_tree.put(key, value, False)
                     elif isinstance(value, list):
                         config_tree.put(key, value, False)

)

gilles-duboscq avatar May 27 '16 11:05 gilles-duboscq

There are also these related issues:

Issue 1

foo.bar = [1, 2]
foo.bar = ${foo.bar} [3, 4]

Parsing this config fails with this error: pyhocon.exceptions.ConfigSubstitutionException: Cannot resolve ${foo.bar}: (line: 2, col: 11). Check for cycles.

Issue 2

foo.bar = [1, 2]
foo.bar += [3, 4]

Parsing this config fails with this error: AttributeError: 'bool' object has no attribute 'count'

Issue 3

foo.bar = [1, 2]
foo {
    bar += [3, 4]
}

Parsing this config results in this unexpected config:

{
  "foo": {
    "bar": [
      3,
      4
    ]
  }
}

Expected is this config:

{
  "foo": {
    "bar": [
      1,
      2,
      3,
      4
    ]
  }
}

mtueng avatar Nov 16 '17 15:11 mtueng

Similar here:

default { setting { format: "file" } }, setting-specific: { setting: ${default.setting}, setting.mode: append }

The expected output for setting-specific is: ` ConfigTree([('setting', ConfigTree([('format', 'file'), ('mode', 'append')]))]))])

But, it lost the param 'format':

ConfigTree([('setting', ConfigTree([('mode', 'append')]))]))]

ChouchouDev avatar Oct 01 '20 15:10 ChouchouDev