Skip to content

Commit 52d77b1

Browse files
Strip Hebrew vowel characters from real length calculation
Hebrew writing has two separate accents / vowels under letters. In testing, all fonts properly handle this
1 parent f2bb69d commit 52d77b1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/cli/cli.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,12 @@ function safe_substr( $str, $start, $length = false ) {
202202
* @return string
203203
*/
204204
function safe_str_pad( $string, $length ) {
205+
// Hebrew vowel characters
206+
$cleaned_string = preg_replace( '#[\x{591}-\x{5C7}]+#u', '', $string );
205207
if ( function_exists( 'mb_strwidth' ) ) {
206-
$real_length = mb_strwidth( $string, mb_detect_encoding( $string ) );
208+
$real_length = mb_strwidth( $cleaned_string, mb_detect_encoding( $string ) );
207209
} else {
208-
$real_length = safe_strlen( $string );
210+
$real_length = safe_strlen( $cleaned_string );
209211
}
210212
$diff = strlen( $string ) - $real_length;
211213
$length += $diff;

tests/test-cli.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function test_encoded_string_pad() {
2727
$this->assertEquals( 6, strlen( \cli\Colors::pad( 'hello', 6 ) ) );
2828
$this->assertEquals( 7, strlen( \cli\Colors::pad( 'óra', 6 ) ) ); // special characters take one byte
2929
$this->assertEquals( 9, strlen( \cli\Colors::pad( '日本語', 6 ) ) ); // each character takes two bytes
30+
$this->assertEquals( 17, strlen( \cli\Colors::pad( 'עִבְרִית', 6 ) ) ); // process Hebrew vowels
3031

3132
}
3233

0 commit comments

Comments
 (0)