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

Do not escape newline in FixStringFormatExpressions #261

Merged

Conversation

timtebeek
Copy link
Contributor

@timtebeek timtebeek self-assigned this Feb 20, 2024
@timtebeek timtebeek added the bug Something isn't working label Feb 20, 2024
@timtebeek timtebeek force-pushed the do-not-replace-escaped-newline-in-FixStringFormatExpressions branch from f30787a to f3131b9 Compare February 20, 2024 10:31
@Bananeweizen
Copy link
Contributor

Bananeweizen commented Feb 20, 2024

This should work for the given example. But it's not yet perfectly correct, IMO. If you look at a pattern made of 1, 2, 3, 4, 5... consecutive backslashes plus n, then in every second of them the replacement would be okay. It basically depends on whether the number of consecutive backslashes in front of the n is odd or even.
Not sure if it's worth the effort of improving the parsing that much, however, since bigger numbers of backslashes correspond with nested levels of java code generation (my initial example was from a code generator generating java code, therefore having one more level of escaping than normally already). I'm fine with taking this a bug fix.

@timtebeek
Copy link
Contributor Author

I've updated the test to show with 1, 2, 3 and 4 backslashes; I don't see the issue you've mentioned with the results being different between odd and even. Feel free to clarify with an updated test if I missed anything, and thanks again!

@timtebeek timtebeek merged commit b43b53d into main Feb 20, 2024
2 checks passed
@timtebeek timtebeek deleted the do-not-replace-escaped-newline-in-FixStringFormatExpressions branch February 20, 2024 15:59
@Bananeweizen
Copy link
Contributor

@timtebeek The new test is fine and nothing is broken. What I meant is: In your new test example it would be okay to also apply the recipe in line 124 of the test, leading to every second line of the progression being updated. As long as the literal can be split into nonbackslash + \\ + ... + \\ + \n, replacing the newline is okay.
But really, we don't need to improve the code, this is quite esoteric. :)

@timtebeek
Copy link
Contributor Author

ah cheers, yes that makes sense, but indeed I'd hope no one is relying on us to clean that up 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

FixStringFormatExpressions wrongly replaces \\n
2 participants