File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 44
55class LatinCharValidator
66{
7+ /**
8+ * exclude C0 controls (basic latin): https://unicode-table.com/en/blocks/basic-latin/
9+ *
10+ * @param string $txt
11+ *
12+ * @return bool
13+ */
714 public static function isValid (string $ txt ): bool
815 {
9- return empty ($ txt ) || preg_match ('/^[\p{Latin}\p{Common}]+$/u ' , $ txt ) > 0 ;
16+ return empty ($ txt ) || (preg_match ('/^[\p{Latin}\p{Common}]+$/u ' , $ txt ) > 0
17+ && preg_match ('/[\x{0000}-\x{001F}]/u ' , $ txt ) == 0 );
1018 }
1119}
Original file line number Diff line number Diff line change @@ -54,5 +54,37 @@ public function testIsValid()
5454 $ this ->assertFalse (LatinCharValidator::isValid ('الْأَبْجَدِيَّة الْعَرَبِيَّة ' ));
5555 // Russian chars
5656 $ this ->assertFalse (LatinCharValidator::isValid ('Меня зовут Мандли ' ));
57+ // Basic Latin C0 controls
58+ $ c0 = [
59+ ' ' ,
60+ ' ' ,
61+ ' ' ,
62+ ' ' ,
63+ ' ' ,
64+ ' ' ,
65+ ' ' ,
66+ ' ' ,
67+ ' ' ,
68+ ' ' ,
69+ ' ' ,
70+ ' ' ,
71+ ' ' ,
72+ ' ' ,
73+ ' ' ,
74+ ' ' ,
75+ ' ' ,
76+ ' ' ,
77+ ' ' ,
78+ ' ' ,
79+ ' ' ,
80+ ' ' ,
81+ ' ' ,
82+ ' ' ,
83+ ' ' ,
84+ ' '
85+ ];
86+ foreach ($ c0 as $ item ) {
87+ $ this ->assertFalse (LatinCharValidator::isValid ('Hello World ' . $ item ));
88+ }
5789 }
5890}
You can’t perform that action at this time.
0 commit comments