-
Notifications
You must be signed in to change notification settings - Fork 46
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
fix(encoder,parser): escape and unescape strings #541
Conversation
I'm not really happy with this but I think I should revisit later rather than spend more time on it now. I'd like to refactor string lexing (to validate escapes in more detail) and parsing and also address #319 and block string indentation at that time. For now this PR should improve the string printing in apollo-encoder so it doesn't produce invalid output anymore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a comment on formatting block string values. otherwise looks good!
yea, string parsing needs a brand new coat of paint. will probably be easier to solve multi-error lexing issue too.
the parser unescaping implementation that i have here does the wrong thing for block strings btw. As block strings don't actually support escapes except for |
This PR improves the string value printing in apollo-encoder. It tries to sensibly decide between a multi-line block string, a single-line block string, and a non-block string depending on the contents it needs to print. It escapes special characters when writing non-block strings. When writing block strings, only
"""
is escaped as\"""
so the block isn't ended prematurely.The parser's
String::from(StringValue)
implementation also un-escapes characters.