Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/catch2/internal/catch_textflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ namespace Catch {
m_it--;
}
// Skip back over UTF-8 continuation bytes to the leading byte
while ( isUtf8ContinuationByte( *m_it ) ) {
assert( m_it != m_string->begin() );
while ( m_it != m_string->begin() &&
isUtf8ContinuationByte( *m_it ) ) {
m_it--;
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/SelfTest/IntrospectiveTests/TextFlow.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,25 @@ TEST_CASE( "TextFlow::AnsiSkippingString iterates UTF-8 codepoints",
}
}

TEST_CASE( "TextFlow::AnsiSkippingString handles invalid UTF-8",
"[TextFlow][ansiskippingstring][regression]" ) {
SECTION( "Continuation byte at the start" ) {
// 0x80 is a continuation byte
AnsiSkippingString str( "\x80" );
auto it = str.end();
--it;
CHECK( it == str.begin() );
CHECK( *it == static_cast<char>( 0x80 ) );
}
SECTION( "Multiple continuation bytes at the start" ) {
AnsiSkippingString str( "\x80\x80\x80" );
auto it = str.end();
--it;
CHECK( it == str.begin() );
CHECK( *it == static_cast<char>( 0x80 ) );
}
}

TEST_CASE( "TextFlow::Column wraps UTF-8 text correctly",
"[TextFlow][column][approvals]" ) {
// "äöü äöü äöü" = 11 codepoints, 17 bytes
Expand Down
Loading