diff --git a/components/layout_2020/flow/inline/text_run.rs b/components/layout_2020/flow/inline/text_run.rs index 126fd3a9893..e9b9385d23f 100644 --- a/components/layout_2020/flow/inline/text_run.rs +++ b/components/layout_2020/flow/inline/text_run.rs @@ -225,6 +225,7 @@ impl TextRunSegment { let mut whitespace = slice.end..slice.end; let mut rev_char_indices = word.char_indices().rev().peekable(); + let mut ends_with_whitespace = false; let ends_with_newline = rev_char_indices .peek() .map_or(false, |&(_, character)| character == '\n'); @@ -232,6 +233,7 @@ impl TextRunSegment { .take_while(|&(_, character)| char_is_whitespace(character)) .last() { + ends_with_whitespace = true; whitespace.start = slice.start + first_white_space_index; // If line breaking for a piece of text that has `white-space-collapse: break-spaces` there @@ -252,10 +254,7 @@ impl TextRunSegment { // If there's no whitespace and `word-break` is set to `keep-all`, try increasing the slice. // TODO: This should only happen for CJK text. - let can_break_anywhere = text_style.word_break == WordBreak::BreakAll || - text_style.overflow_wrap == OverflowWrap::Anywhere || - text_style.overflow_wrap == OverflowWrap::BreakWord; - if whitespace.is_empty() && + if !ends_with_whitespace && *break_index != self.range.end && text_style.word_break == WordBreak::KeepAll && !can_break_anywhere diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index bf77ff912e0..b202969a1d3 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -254546,6 +254546,19 @@ {} ] ], + "break-spaces-with-word-break-001.html": [ + "ee31fd627130eeb40fd22d0b9bc4fa6e9eb3aca7", + [ + null, + [ + [ + "/css/reference/ref-filled-green-100px-square.xht", + "==" + ] + ], + {} + ] + ], "control-chars-000.html": [ "b038fe9a90d3b8b9cb3bde7fd46396c7121688c9", [ diff --git a/tests/wpt/tests/css/css-text/white-space/break-spaces-with-word-break-001.html b/tests/wpt/tests/css/css-text/white-space/break-spaces-with-word-break-001.html new file mode 100644 index 00000000000..ee31fd62713 --- /dev/null +++ b/tests/wpt/tests/css/css-text/white-space/break-spaces-with-word-break-001.html @@ -0,0 +1,24 @@ + + +
Test passes if there is a filled green square and no red.
+