File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Test/Unit/Model/Attribute/Data Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,9 @@ public function validateValue($value)
7979 return $ errors ;
8080 }
8181
82+ // if string with diacritics encode it.
83+ $ value = $ this ->encodeDiacritics ($ value );
84+
8285 $ validateLengthResult = $ this ->validateLength ($ attribute , $ value );
8386 $ errors = array_merge ($ errors , $ validateLengthResult );
8487
@@ -173,4 +176,19 @@ private function validateInputRule(string $value): array
173176 $ result = $ this ->_validateInputRule ($ value );
174177 return \is_array ($ result ) ? $ result : [];
175178 }
179+
180+ /**
181+ * Encode strings with diacritics for validate.
182+ *
183+ * @param array|string $value
184+ * @return array|string
185+ */
186+ private function encodeDiacritics ($ value ): array |string
187+ {
188+ $ encoded = $ value ;
189+ if (is_string ($ value )) {
190+ $ encoded = iconv ('UTF-8 ' , 'ASCII//TRANSLIT//IGNORE ' , $ value );
191+ }
192+ return $ encoded ;
193+ }
176194}
Original file line number Diff line number Diff line change @@ -199,6 +199,16 @@ public function alphanumWithSpacesDataProvider(): array
199199 ];
200200 }
201201
202+ /**
203+ * Test for string with diacritics validation
204+ */
205+ public function testValidateValueStringWithDiacritics (): void
206+ {
207+ $ inputValue = "á â à å ä ð é ê è ë í î ì ï ó ô ò ø õ ö ú û ù ü æ œ ç ß a ĝ ń ŕ ý ð ñ " ;
208+ $ expectedResult = true ;
209+ self ::assertEquals ($ expectedResult , $ this ->model ->validateValue ($ inputValue ));
210+ }
211+
202212 /**
203213 * @param array $attributeData
204214 * @return Attribute
You can’t perform that action at this time.
0 commit comments