Repository navigation
Conversation
get_comment() copied comment text verbatim into a triple-quoted docstring, so a comment containing """ ended the docstring and the rest of the line became code in the generated module, which ran on import. Escape backslashes and double quotes before emitting the docstring. Fixes danielgtaylor#684
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #684.
get_comment()insrc/betterproto/plugin/models.pycopied.protocomment text verbatim into a triple-quoted docstring. A comment containing"""ended the docstring and the rest of the comment became code in the generated module, which ran when the module was imported.This escapes backslashes and double quotes in each comment line before the docstring is built. Escaping every
"(not only""") also covers a comment that ends with a quote, which would otherwise produce""""and break the generated file. The docstrings read the same at runtime; only the source representation changes.Test:
tests/inputs/documentation_escapinghas comments with""", embedded and trailing quotes and a backslash;tests/test_documentation_escaping.pyimports the generated module and checks the docstring text. Without the fix the plugin fails to generate this input; with it, the new test and the existingtest_documentation.pypass.