Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustdoc/html/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ impl fmt::Display for EscapeBodyTextWithWbr<'_> {
} else if (s.contains(':') && !next_is_colon())
|| (s.contains('_') && !next_is_underscore())
{
EscapeBodyText(&text[last..i + 1]).fmt(fmt)?;
// `i + s.len()`, not `i + 1`: a cluster containing `_` or `:` can still be
// several bytes long, because UAX#29 GB9b joins a `Prepend` character to the
// one that follows it.
EscapeBodyText(&text[last..i + s.len()]).fmt(fmt)?;
fmt.write_str("<wbr>")?;
last = i + 1;
last = i + s.len();
}
}
if last < text.len() {
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/escape/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ fn escape_body_text_with_wbr() {
assert_eq!(&E("ṼẽçÑñéå").to_string(), "Ṽẽç<wbr>Ññéå");
assert_eq!(&E("V\u{0300}e\u{0300}c\u{0300}D\u{0300}e\u{0300}q\u{0300}u\u{0300}e\u{0300}u\u{0300}e\u{0300}").to_string(), "V\u{0300}e\u{0300}c\u{0300}<wbr>D\u{0300}e\u{0300}q\u{0300}u\u{0300}e\u{0300}u\u{0300}e\u{0300}");
assert_eq!(&E("LPFNACCESSIBLEOBJECTFROMWINDOW").to_string(), "LPFNACCESSIBLEOBJECTFROMWINDOW");
// clusters where the `_` or `:` is not the first byte (UAX#29 GB9b `Prepend`)
assert_eq!(&E("abc\u{0D4E}_defgh").to_string(), "abc\u{0D4E}_<wbr>defgh");
assert_eq!(&E("abc\u{0605}:defgh").to_string(), "abc\u{0605}:<wbr>defgh");
assert_eq!(&E("first_\u{0300}second").to_string(), "first_\u{0300}<wbr>second");
}
// property test
#[test]
Expand Down
8 changes: 8 additions & 0 deletions tests/rustdoc-html/item-name-grapheme-cluster-wbr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Regression test for #160231: `<wbr>` insertion sliced mid-character on an item name whose
// grapheme cluster starts with a `Prepend` character and contains `_`.

#![crate_name = "foo"]
#![allow(mixed_script_confusables, non_camel_case_types)]

//@ hasraw foo/index.html 'abcൎ_<wbr>defgh'
pub struct abcൎ_defgh;
Loading