File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,12 @@ impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
9696 let _ = it. next ( ) ; // don't insert wbr before first char
9797 while let Some ( ( i, s) ) = it. next ( ) {
9898 let pk = it. peek ( ) ;
99+ if s. chars ( ) . all ( |c| c. is_whitespace ( ) ) {
100+ // don't need "First <wbr>Second"; the space is enough
101+ EscapeBodyText ( & text[ last..i] ) . fmt ( fmt) ?;
102+ last = i;
103+ continue ;
104+ }
99105 let is_uppercase = || s. chars ( ) . any ( |c| c. is_uppercase ( ) ) ;
100106 let next_is_uppercase =
101107 || pk. map_or ( true , |( _, t) | t. chars ( ) . any ( |c| c. is_uppercase ( ) ) ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ fn escape_body_text_with_wbr() {
99 // real(istic) examples
1010 assert_eq ! ( & E ( "FirstSecond" ) . to_string( ) , "First<wbr>Second" ) ;
1111 assert_eq ! ( & E ( "First_Second" ) . to_string( ) , "First<wbr>_Second" ) ;
12+ assert_eq ! ( & E ( "First Second" ) . to_string( ) , "First Second" ) ;
13+ assert_eq ! ( & E ( "First HSecond" ) . to_string( ) , "First HSecond" ) ;
14+ assert_eq ! ( & E ( "First HTTPSecond" ) . to_string( ) , "First HTTP<wbr>Second" ) ;
15+ assert_eq ! ( & E ( "First SecondThird" ) . to_string( ) , "First Second<wbr>Third" ) ;
1216 assert_eq ! ( & E ( "First<T>_Second" ) . to_string( ) , "First<<wbr>T><wbr>_Second" ) ;
1317 assert_eq ! ( & E ( "first_second" ) . to_string( ) , "first<wbr>_second" ) ;
1418 assert_eq ! ( & E ( "MY_CONSTANT" ) . to_string( ) , "MY<wbr>_CONSTANT" ) ;
You can’t perform that action at this time.
0 commit comments