forked from magento/magento2-functional-testing-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleUtils.php
32 lines (29 loc) · 1.05 KB
/
ModuleUtils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace Magento\FunctionalTestingFramework\Module\Util;
class ModuleUtils
{
/**
* Module util function that returns UTF-8 encoding string with control/invisible characters removed,
* and it returns the original string when on error.
*
* @param string $input
* @return string
*/
public function utf8SafeControlCharacterTrim(string $input): string
{
// Convert $input string to UTF-8 encoding
$convInput = iconv("ISO-8859-1", "UTF-8//IGNORE", $input);
if ($convInput !== false) {
// Remove invisible control characters, unused code points and replacement character
// so that they don't break xml test results for Allure
$cleanInput = preg_replace('/[^\PC\s]|\x{FFFD}/u', '', $convInput);
if ($cleanInput !== null) {
return $cleanInput;
} else {
$err = preg_last_error_msg();
print("MagentoCLI response preg_replace() with error $err.\n");
}
}
return $input;
}
}