akkadotnet / HOCON

C# implementation of Lightbend's HOCON (Human-Optimized Object Configuration Notation)
Apache License 2.0
137 stars 39 forks source link

Substitution path will not be resolved properly if path is used in "included file" #373

Open holonsoftFounder opened 2 years ago

holonsoftFounder commented 2 years ago

found in Hocon.dll, version 2.0.4 environment: .net 4.8, VS2022

The object path is evaluted in a wrong way if evalutation in a included file

Let's image following main file:

import-rules
{
    default-data-first-page = "1"
    default-data-last-page = "9999"         
    default-data-converter = "buildin"
    default-data-ignore-case = "true"

    default-range-tolerance-x = "4"         
    default-range-tolerance-y = "0"

    default-data-field-name = "Value"

    pdf-import-rulesets =
    [
        include required(file(".\\PdfImportRules_TWDInvoice.conf"))
    ]
}

and the file to be included:

{
    has-id = "{789C90B4-25A3-46C9-A1E2-1C0DF6352783}"
    has-type-id = "ExternalDocumentsType.TWDInvoice"
    has-friendly-name = "TWD Rechnung"

    detection-rules =
    [
        {
            has-id = "{403840A8-6C18-4A79-936A-8C944A36E9D2}"
            has-friendly-name = "detect: Rechnung"
            data-converter = ${import-rules.default-data-converter}
            data-ignore-case = ${import-rules.default-data-ignore-case}

            data-is-static = "true"
            data-type = "string"
            data-content = "rechnung"

            data-range-tolerance-x = ${import-rules.default-range-tolerance-x}
            data-range-tolerance-y = ${import-rules.default-range-tolerance-y}

            data-on-page = ${import-rules.default-data-first-page}
            data-start-point-x = "339.05"
            data-start-point-y = "656.11"
            data-endpoint-x = "384.87"
            data-endpoint-y = "657.42"
        }
      ]
}

the parsing gets an exception:

Unresolved substitution: import-rules.pdf-import-rulesets.import-rules.default-data-converter. At path 'import-rules.pdf-import-rulesets.import-rules.default-data-converter', line 11, position 25.

Putting the content of the included file directly into main file (and remove include statement) resolves all data as expected. So, if a file is included, the path is not evaluates as ABSOLUTE but as relative path and is concatinated. In our example the "import-rules.pdf-import-rulesets" part of path is wrong

Complete files are attachted in zip file.

ImportRules.zip