File tree 2 files changed +10
-0
lines changed
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> {
96
96
let _ = it. next ( ) ; // don't insert wbr before first char
97
97
while let Some ( ( i, s) ) = it. next ( ) {
98
98
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
+ }
99
105
let is_uppercase = || s. chars ( ) . any ( |c| c. is_uppercase ( ) ) ;
100
106
let next_is_uppercase =
101
107
|| 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() {
9
9
// real(istic) examples
10
10
assert_eq ! ( & E ( "FirstSecond" ) . to_string( ) , "First<wbr>Second" ) ;
11
11
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" ) ;
12
16
assert_eq ! ( & E ( "First<T>_Second" ) . to_string( ) , "First<<wbr>T><wbr>_Second" ) ;
13
17
assert_eq ! ( & E ( "first_second" ) . to_string( ) , "first<wbr>_second" ) ;
14
18
assert_eq ! ( & E ( "MY_CONSTANT" ) . to_string( ) , "MY<wbr>_CONSTANT" ) ;
You can’t perform that action at this time.
0 commit comments