-
Notifications
You must be signed in to change notification settings - Fork 101
Fix escaping bugs in UseTextBlocks #215
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
kunli2
merged 4 commits into
openrewrite:main
from
aksh1618:aksh1618/fixUseTextBlocksEscaping
May 3, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3528f94
fix backslashes not escaped in UseTextBlocks
aksh1618 1d09657
fix triple quotes inside string not escaped in UseTextBlocks
aksh1618 20173f6
add test for ending quote handling in UseTextBlocks
aksh1618 ac5610a
add clarifying comments for different cases handled in UseTextBlocks
aksh1618 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
do you know why the triple quotes are transformed to
\"\"\\\"
but not\\\"\"\"
, the difference is the 1st or 3rd quote is escaped.I found for an 8 quotes case:
s1 and s2 are equivalent, however,
doesn't compile unless change it to
which makes me think to escape the 3rd quote instead of 1st is like magic.
Do you have any insight of this?
Uh oh!
There was an error while loading. Please reload this page.
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.
@kunli2 I went for escaping the third quote instead of the first to optimize for the number of escapes needed in case of n number of continuous quotes (For example: 2 escapes instead of 3 in case of 8 quotes). Another thing I noticed was that IDEA by default escapes the third quote as well, for instance if you copy-paste a series of quotes inside a text block.
In your examples, I can't see any difference between s2 & s3 (both), did GitHub formatting probably make them look the same? Could you share it in some other form such as a gist so that I can try to understand it better, maybe then I could answer it better?.
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.
hi @aksh1618 , yes, I also found IDE by default escapes the 3rd quote.
what I noticed is below, the first statement in the code doesn't compile (
\"""\"""""
doesn't compile but\"""\"""\""\
does). I guess that is the reason why IDEA escapes the 3rd quote instead of 1st.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.
sorry for the confusion in my 1st comment, I have revised the code in the comment.
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.
@kunli2 thanks for clarifying, it's a very good example! So to summarize, in this case if we're replacing programmatically successively, escaping the first one would not work as it leads to code that doesn't compile due to 4 quotes left together. So now it makes sense why they went with the third one as well instead of having to write a more complex replacement algorithm for handling leftover quotes 👍
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.
@aksh1618 yeah, it makes sense! thanks for fixing and contribution again!