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

Line breaks in string literal + ascii escape code changes meaning #4471

Open
aDotInTheVoid opened this issue Oct 14, 2020 · 1 comment · May be fixed by #5483 or #5976
Open

Line breaks in string literal + ascii escape code changes meaning #4471

aDotInTheVoid opened this issue Oct 14, 2020 · 1 comment · May be fixed by #5483 or #5976
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release only-with-option requires a non-default option value to reproduce poor-formatting

Comments

@aDotInTheVoid
Copy link
Member

Input

const ASCII_ESCAPE: &str = "id\u{1f}1\u{1f}/Users/nixon/dev/rs/gitstatusd\u{1f}1c9be4fe5460a30e70de9cbf99c3ec7064296b28\u{1f}master\u{1f}\u{1f}\u{1f}\u{1f}\u{1f}7\u{1f}0\u{1f}1\u{1f}0\u{1f}1\u{1f}0\u{1f}0\u{1f}0\u{1f}\u{1f}0\u{1f}0\u{1f}0\u{1f}\u{1f}\u{1f}0\u{1f}0\u{1f}0\u{1f}0";

Output

const ASCII_ESCAPE: &str = "id\u{1f}1\u{1f}/Users/nixon/dev/rs/gitstatusd\\
                            u{1f}1c9be4fe5460a30e70de9cbf99c3ec7064296b28\u{1f}master\u{1f}\u{1f}\\
                            u{1f}\u{1f}\u{1f}7\u{1f}0\u{1f}1\u{1f}0\u{1f}1\u{1f}0\u{1f}0\u{1f}0\\
                            u{1f}\u{1f}0\u{1f}0\u{1f}0\u{1f}\u{1f}\u{1f}0\u{1f}0\u{1f}0\u{1f}0";

Expected output

const ASCII_ESCAPE: &str = "id\u{1f}1\u{1f}/Users/nixon/dev/rs/gitstatusd\
                            \u{1f}1c9be4fe5460a30e70de9cbf99c3ec7064296b28\u{1f}master\u{1f}\u{1f}\
                            \u{1f}\u{1f}\u{1f}7\u{1f}0\u{1f}1\u{1f}0\u{1f}1\u{1f}0\u{1f}0\u{1f}0\
                            \u{1f}\u{1f}0\u{1f}0\u{1f}0\u{1f}\u{1f}\u{1f}0\u{1f}0\u{1f}0\u{1f}0";

The two outputs are different. Playground. As the split is across the "\u{1f}" it breaks this up and instead creates a \\", which means the line gets a "\" and indentation as the "\" that was inserted was escaped by the "\" that was ment to escape the hex literal.

rustfmt.toml

format_strings = true

Meta

  • rustfmt version: rustfmt 1.4.22-nightly (97d03010 2020-10-04)
  • From where did you install rustfmt?: rustup
davidBar-On added a commit to davidBar-On/rustfmt that referenced this issue Nov 13, 2020
@calebcartwright calebcartwright added the only-with-option requires a non-default option value to reproduce label Nov 26, 2020
calebcartwright pushed a commit that referenced this issue Dec 9, 2020
* Issue #4471 - not wrap strings at backslash

* Changes according to comments to the fix PR #4524

* Some more modifications to improve the code per comments received
@calebcartwright calebcartwright added the 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release label Dec 9, 2020
@karyon
Copy link
Contributor

karyon commented Oct 28, 2021

repro'd with 1.4.38

ahl added a commit to ahl/rustfmt that referenced this issue Dec 7, 2023
@ahl ahl linked a pull request Dec 7, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release only-with-option requires a non-default option value to reproduce poor-formatting
Projects
None yet
4 participants