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

fix: emit attribute with escaped quote and backslash #445

Merged

Conversation

sssooonnnggg
Copy link
Contributor

The fbs below cannot be compiled because of unescaped double quotes.

attribute custom_attribute;
namespace test;
table foo
{
    bar: int (custom_attribute: "hello, \"world\"");
}

This PR fixes it.

@jamescourtney
Copy link
Owner

Thanks! Are there other escape characters we need to be mindful of as well?

@jamescourtney
Copy link
Owner

I'd appreciate you adding a unit test here. FlatSharp.Compiler.UnitTests is the correct project.

@sssooonnnggg
Copy link
Contributor Author

sssooonnnggg commented Oct 24, 2024

Thank you for your review.
According to the source code of flatc's parser (idl_parser.cpp), we need to handle three cases: \", \', \\
\' does not need to be escaped in FlatSharp because "'" is a valid string in C#
In addition to \", we also need to handle \\
I will handle it and add unit tests later.

@sssooonnnggg
Copy link
Contributor Author

@jamescourtney Please review again, process backslash and double quote, some unit tests added😊

@sssooonnnggg sssooonnnggg changed the title fix: emit attribute with escaped quote fix: emit attribute with escaped quote and backslash Oct 24, 2024
@jamescourtney
Copy link
Owner

Thanks for your efforts here! I'm a little perplexed that flatc doesn't handle this for me, since it is the grammar parser after all. In any case, I'll take a look later today and hopefully approve.

@sssooonnnggg
Copy link
Contributor Author

FYI,the string readed from flatc parser is converted from an escaped string in fbs file to the original string. When we generate C# code with a string literal, we need to convert the original string back to an escaped string.

@jamescourtney jamescourtney merged commit a86c8ae into jamescourtney:main Oct 27, 2024
6 checks passed
@sssooonnnggg sssooonnnggg deleted the fix-attribute-with-quote branch November 1, 2024 02:45
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.

2 participants