Skip to content
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

Avoid to generate text with ending backslash #225

Merged
merged 6 commits into from
Oct 6, 2019

Conversation

gabrielelana
Copy link
Contributor

Fixes half of #198

We were wondering why you didn't use genPrefixMap in genToml, seems like the second problem stated in #198 it might be related to genPrefixMap, are we on the right path?

Proudly made by @sphaso and @gabrielelana at "Open Source Saturday Milano"

Open Source Saturday

@chshersh chshersh added the test Testing (unit, properties) label Oct 5, 2019
Copy link
Contributor

@chshersh chshersh left a comment

Choose a reason for hiding this comment

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

@gabrielelana Thanks for your contribution! I appreciate improvements to tests 🙂

We were wondering why you didn't use genPrefixMap in genToml

Actually, this seems like a unfortunate thing. genPrefixMap should be used to generate TOML. Could, you, please, try to use genPrefixMap instead of the current solution?

genText :: MonadGen m => m Text
genText = fmap Text.concat $ Gen.list (Range.constant 0 256) $ Gen.choice
genText :: (MonadGen m, GenBase m ~ Identity) => m Text
genText = Gen.filter invalidEscape $ fmap Text.concat $ Gen.list (Range.constant 0 256) $ Gen.choice
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue #198 is about not generating \\ inside TOML keys. However, I believe that genText is used not only for keys but for something else. So filtering here is not exactly correct. Instead, you should filter only when generating TOML keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think genText is not used to generate keys but I also thought that a generic text should not end with a single escape like "aaa\"

Comment on lines 342 to 346
invalidEscape :: Text -> Bool
invalidEscape t
| t == Text.empty = True
| Text.last t == '\\' = False
| otherwise = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please some documentation to this function and some examples of valid and invalid strings? And ideally with the link to TOML spec where it says that "\" cannot be a valid key. I'm afraid that this this solution solves the problem partially. Is the following key valid?

"\x"

I think that no, but it still can be genarated. I'm okay to accept this PR as a partial solution, but let's document some cases of what this function covers and what it doesn't cover 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look at validText in the last commit if it's what you asked

validString ('\\':'"':s) = validString s
validString ('\\':'\'':t) = validString t
validString ('\\':'\\':t) = validString t
validString ('\\':'u':n1:n2:n3:n4:t) = (all Char.isHexDigit [n1, n2, n3, n4]) && validString t
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is becoming too complicated... I'm afraid it will require some time to understand what's happening here and make sure that there's no better approach... At this point the previous solution doesn't look that bad 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bummer, I thought it was pretty slick 😂 Anyway, no problem to revert it

@gabrielelana
Copy link
Contributor Author

@chshersh let me know what do you think

Copy link
Contributor

@chshersh chshersh left a comment

Choose a reason for hiding this comment

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

@gabrielelana This should be good for now 👍 Thanks for your contribution! The generator can be patched again if we ever have troubles with it 🙂

@chshersh chshersh merged commit 1d54153 into kowainik:master Oct 6, 2019
@chshersh chshersh added this to the v1.2.0.0 milestone Oct 9, 2019
@chshersh chshersh added the Hacktoberfest https://hacktoberfest.digitalocean.com/ label Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest https://hacktoberfest.digitalocean.com/ test Testing (unit, properties)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants