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

Backport #4524 and fix #5138 - proper wrap strings with escape backslash #5483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

davidBar-On
Copy link
Contributor

Backport #4524
Fixes #5138

Backport of #4524 that fixes #4471 with enhancements to fix #5138.

src/string.rs Outdated
Comment on lines 227 to 228
// Ensure break is not after an escape '\' as it will "escape" the `\` that is added
// for concatenating the two parts of the broken line.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this rephrasing could help explain that we're trying not to escape any line continuation characters that we add when we break the string.

Suggested change
// Ensure break is not after an escape '\' as it will "escape" the `\` that is added
// for concatenating the two parts of the broken line.
// Ensure break is not after an escape '\' as it will "escape" the line continuation `\`
// that is added for concatenating the two parts of the broken line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment enhanced in line with the requested change.

src/string.rs Outdated
Comment on lines 236 to 241
// There is a non-`\` to the left
Some(non_backslash_index) => (index - non_backslash_index) % 2,
// Only `\` to the left
None => (index + 1) % 2,
};
// Make sure break is after even number (including zero) of `\`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you could elaborate more on these comments or rephrase them somehow. When I read them I feel like there are some details that are missing. For example, why do we need to make sure the break is after an even number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhanced the comments and moved some to a more appropriate place. I hope they are sufficiently clear now.

Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay on the re-review. After taking another look at this with the updated comments I feel like it's a lot clearer to understand what's going on with the code, and I think the logic that you've laid out to prevent breaking on on \\ characters makes sense.

I'm happy to move forward with this. We're waiting for a few PRs to land in rust-lang/rust, so going to mark this as ready-to-merge, but won't merge it just yet.

@purplesyringa
Copy link

Are there any plans to merge this? I've just stumbled upon this bug on nightly.

@ytmimi
Copy link
Contributor

ytmimi commented Oct 22, 2023

@purplesyringa thanks for reaching out, and sorry to hear that you hit this issue The team is getting ready for another release right now, and we'll likely revisit this PR for the following release.

@ahl ahl mentioned this pull request Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants