Skip to content

fixed bug where dot notation doesn't work properly #72

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 3 commits into from
Dec 7, 2018

Conversation

imacks
Copy link
Contributor

@imacks imacks commented Nov 28, 2018

This is an attempt at addressing issue #71
The bug is caused by attempting to add a new key to a merged object, which is not the same as the field's actual underlying value.

Dot notation doesn't work when the parent is a merged object. This should fix the issue.
@imacks imacks mentioned this pull request Nov 28, 2018
converting path to string did not perform proper escaping. this fixes the issue.
Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

Looks good, just need a few changes.

foreach (string subPath in this)
{
// #todo escape newline chars in path?
if (subPath.NeedTripleQuotes())
Copy link
Contributor

@Arkatufus Arkatufus Dec 1, 2018

Choose a reason for hiding this comment

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

This isn't needed, triple quotes in paths are rejected during creation, as they are illegal by HOCON specification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my code did not illustrate my concern properly. The problem I have is that a key is technically allowed to contain \n or other control characters. This creates a problem when you need to reference it in a path, as we can't triple quote it. I guess the solution is to escape all the offending characters automatically, which I was too lazy to implement.

To be clear, my code above does not fully address the concern above. Any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

well, triple quotes in field keys are not allowed in the HOCON specification, and it is enforced when the key is created/parsed, so there is no need to check for a triple quote there.

@@ -124,6 +124,17 @@ public static bool Contains(this string s, char c)
return s.IndexOf(c) != -1;
}

public static bool ContainsHoconWhitespaceExceptNewLine(this string s)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is is covered by the NeedTripleQuotes() string extension.

Copy link
Contributor Author

@imacks imacks Dec 2, 2018

Choose a reason for hiding this comment

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

Again, I was worried that a key may contain whitespace (such as my key). NeedTripleQuotes calls NeedQuotes, which I understand does not check for whitespace. Did not cross my mind, but would a path such as foo.my key.bar be valid (or does it have to be foo."my key".bar)?

Copy link
Contributor

Choose a reason for hiding this comment

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

foo."my.key".bar and foo."my long spacious key".bar are both legal, but not foo."""my\nkey""".bar. Your concern is correct, there is a bug in Path parsing. My point is that, instead of making another extension method, you should fix the NeedTripleQuotes() method instead

@@ -182,5 +193,19 @@ public static bool NeedQuotes(this string s)
public static bool NeedTripleQuotes(this string s)
=> s.NeedQuotes() && s.Contains(Utils.NewLine);

public static string AddQuotesIfRequired(this string s)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use ToHoconSafe() string extension instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I was concerned that a key may contain the \ character. Would that be a problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't be a problem, unless you can found a case where there is a problem? If there is a problem, then ToHoconSafe() should be fixed too.

- less modification on existing extensions
- support for converting keys with special values to path: `\n`, (empty), `"`, `.` and `\`.
@imacks
Copy link
Contributor Author

imacks commented Dec 6, 2018

hi i made some modifications to my pr based on your comments :)

@Arkatufus
Copy link
Contributor

Looking good. We'll try to improve the backslash substitution problem later, your solution is good for now 👍

@Aaronontheweb Aaronontheweb merged commit 48f7b1f into akkadotnet:dev Dec 7, 2018
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.

3 participants