Skip to content

Commit

Permalink
Don't remove non-breaking space in block comment with bare lines
Browse files Browse the repository at this point in the history
Fixes 5638

Block comments with bare lines are those that have lines without leading
`*` characters. When reformatting these comments we should be mindful
not to remove leading non-breaking spaces (U+00A0).
  • Loading branch information
ytmimi committed Jan 5, 2023
1 parent ee2bed9 commit 5da39b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,10 @@ pub(crate) fn trim_left_preserve_layout(
trimmed = false;
line
} else {
line.trim().to_owned()
// use `is_ascii_whitespace` so we don't remove Non-breaking spaces
line.trim_start_matches(|c: char| c.is_ascii_whitespace())
.trim_end()
.to_owned()
};
trimmed_lines.push((trimmed, line, prefix_space_width));

Expand Down
4 changes: 4 additions & 0 deletions tests/target/issue_5638.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
normal spaces
  non-breaking spaces
*/

0 comments on commit 5da39b4

Please sign in to comment.