File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,17 @@ impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
108108 || pk. map_or ( true , |( _, t) | t. chars ( ) . any ( |c| c. is_uppercase ( ) ) ) ;
109109 let next_is_underscore = || pk. map_or ( true , |( _, t) | t. contains ( '_' ) ) ;
110110 let next_is_colon = || pk. map_or ( true , |( _, t) | t. contains ( ':' ) ) ;
111- if i - last > 3 && is_uppercase ( ) && !next_is_uppercase ( ) {
111+ // Check for CamelCase.
112+ //
113+ // `i - last > 3` avoids turning FmRadio into Fm<wbr>Radio, which is technically
114+ // correct, but needlessly bloated.
115+ //
116+ // is_uppercase && !next_is_uppercase checks for camelCase. HTTPSProxy,
117+ // for example, should become HTTPS<wbr>Proxy.
118+ //
119+ // !next_is_underscore avoids turning TEST_RUN into TEST<wbr>_<wbr>RUN, which is also
120+ // needlessly bloated.
121+ if i - last > 3 && is_uppercase ( ) && !next_is_uppercase ( ) && !next_is_underscore ( ) {
112122 EscapeBodyText ( & text[ last..i] ) . fmt ( fmt) ?;
113123 fmt. write_str ( "<wbr>" ) ?;
114124 last = i;
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ fn escape_body_text_with_wbr() {
2424 assert_eq ! ( & E ( "first:second" ) . to_string( ) , "first:<wbr>second" ) ;
2525 assert_eq ! ( & E ( "first::second" ) . to_string( ) , "first::<wbr>second" ) ;
2626 assert_eq ! ( & E ( "MY_CONSTANT" ) . to_string( ) , "MY_<wbr>CONSTANT" ) ;
27+ assert_eq ! (
28+ & E ( "_SIDD_MASKED_NEGATIVE_POLARITY" ) . to_string( ) ,
29+ "_SIDD_<wbr>MASKED_<wbr>NEGATIVE_<wbr>POLARITY"
30+ ) ;
2731 // a string won't get wrapped if it's less than 8 bytes
2832 assert_eq ! ( & E ( "HashSet" ) . to_string( ) , "HashSet" ) ;
2933 // an individual word won't get wrapped if it's less than 4 bytes
You can’t perform that action at this time.
0 commit comments