This repository was archived by the owner on May 28, 2025. It is now read-only.
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 @@ -97,6 +97,12 @@ impl<'a> fmt::Display for EscapeBodyTextWithWbr<'a> {
9797 let _ = it. next ( ) ; // don't insert wbr before first char
9898 while let Some ( ( i, s) ) = it. next ( ) {
9999 let pk = it. peek ( ) ;
100+ if s. chars ( ) . all ( |c| c. is_whitespace ( ) ) {
101+ // don't need "First <wbr>Second"; the space is enough
102+ EscapeBodyText ( & text[ last..i] ) . fmt ( fmt) ?;
103+ last = i;
104+ continue ;
105+ }
100106 let is_uppercase = || s. chars ( ) . any ( |c| c. is_uppercase ( ) ) ;
101107 let next_is_uppercase =
102108 || 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