Skip to content

Commit 8a932e9

Browse files
Fix UTF8 cyrillic line ending issue
This fixes issue #15 in a very hacky way. The pure cyrillic detection must be replaced with a more generic approach. But for now I could not figure it out. So this hack must do for now.
1 parent bdf4944 commit 8a932e9

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/Output/Util.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static function trimEmptyLines(array $lines): array
4646
*/
4747
public static function normalizeLineEndings(string $text): string
4848
{
49-
return preg_replace('~(BSR_ANYCRLF)*\R~', "\n", $text);
49+
$mod = preg_match('/[\p{Cyrillic}]/u', $text) ? 'u' : '';
50+
return preg_replace('~(*BSR_UNICODE)\R~' . $mod, "\n", $text);
5051
}
5152
}

tests/cli/Output/UtilTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,28 @@ public function testTrimEmptyLinesEmptyLinesAtTheEnd()
7272
/**
7373
* Tests Util::normalizeLineEndings
7474
*/
75-
public function testNormalizeLineEndings(): void
75+
public function testNormalizeLineEndingsASCII(): void
7676
{
7777
$text = "test\ntest\r\ntest\r\ntest";
7878
$this->assertEquals("test\ntest\ntest\ntest", Util::normalizeLineEndings($text));
79+
}
7980

81+
/**
82+
* Tests Util::normalizeLineEndings
83+
*/
84+
public function testNormalizeLineEndingsUTF8(): void
85+
{
8086
$uft8text = "test\ftest\x0btest\r\ntest\x85test";
8187
$this->assertEquals("test\ntest\ntest\ntest\ntest", Util::normalizeLineEndings($uft8text));
8288
}
89+
90+
/**
91+
* Tests Util::normalizeLineEndings
92+
*/
93+
public function testNormalizeLineEndingsCyrillic(): void
94+
{
95+
$cyrillicText = "text: хо\ntext: хо\r\n";
96+
$expected = "text: хо\ntext: хо\n";
97+
$this->assertEquals($expected, Util::normalizeLineEndings($cyrillicText));
98+
}
8399
}

0 commit comments

Comments
 (0)