Skip to content

Fix parsing of quoted keys #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2019

Conversation

IgorFedchenko
Copy link
Contributor

@IgorFedchenko IgorFedchenko commented Dec 11, 2019

Close #125

So, here is the issue: during parsing of hocon object, we need to store object's keys. And with double-quoted keys, if we will include '"' sign in the key, we will not be able to make requests like config.GetInt("a") if a was double-quoted. Or, if we will omit '"' sign when storing the key ) which looks better, and this is what we are doing) - we will loose information that this key was double-quoted.

This information is not that important - until we will try to get value from object by it's path. That is exactly what happens when we call config.GetObject("A") for example - recursively it will iterate children, using keys of the object like hocon paths.

And guess what - for double-quoted key "X.Y" we have hocon path "X.Y" (we do not know that is was double-quoted, so it is handled like X -> Y), but object has X.Y key, and does not have X. So that's why we are getting error.

After some experiments with keeping double-quotes in keys and other stuff, I ended up with idea that it is better to think about such keys lookup as a special case - and each time when we are requesting child by hocon path, I am just checking if full path is preset in object's keys. So for path X.Y it will check X.Y, and then X -> Y.

@IgorFedchenko
Copy link
Contributor Author

I have also reproduced this issue with sample in referenced issue, and ended up with the bug in core library.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


// Sometimes path may be a double-quoted string like "a.b.c" with quotes ommited,
// so check if there is such key first
if (currentObject.TryGetValue(path.ToString(), out var rootField))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb merged commit b9eb927 into akkadotnet:dev Dec 13, 2019
@IgorFedchenko IgorFedchenko deleted the fix/parse-quoted-elements branch December 13, 2019 13:21
Aaronontheweb pushed a commit that referenced this pull request Dec 27, 2019
* Added reproducing test

* Fixed double-quoted paths in object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing fails for quoted elements
2 participants