Skip to content

Commit fe04f75

Browse files
committed
MQE-3267: trim invalid utf-8 characters from response
1 parent ac507c8 commit fe04f75

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ext-intl": "*",
1616
"ext-json": "*",
1717
"ext-openssl": "*",
18+
"ext-iconv": "*",
1819
"allure-framework/allure-codeception": "^1.4",
1920
"aws/aws-sdk-php": "^3.132",
2021
"codeception/codeception": "^4.1",

composer.lock

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ public function magentoCLI($command, $timeout = null, $arguments = null)
584584
$response = $executor->read();
585585
$executor->close();
586586

587-
return $response;
587+
$response = trim($this->safeUtf8Conversion($response));
588+
return $response != "" ? $response : "CLI did not return output.";
588589
}
589590

590591
/**
@@ -1059,4 +1060,29 @@ public function pause($pauseOnFail = false)
10591060

10601061
$this->codeceptPause();
10611062
}
1063+
1064+
/**
1065+
* Return UTF-8 encoding string with control/invisible characters removed, return original string on error.
1066+
*
1067+
* @param string $input
1068+
* @return string
1069+
*/
1070+
private function safeUtf8Conversion(string $input): string
1071+
{
1072+
// Convert $input string to UTF-8 encoding
1073+
$convInput = iconv("ISO-8859-1", "UTF-8//IGNORE", $input);
1074+
if ($convInput !== false) {
1075+
// Remove invisible control characters, unused code points and replacement character
1076+
// so that they don't break xml test results for Allure
1077+
$cleanInput = preg_replace('/[^\PC\s]|\x{FFFD}/u', '', $convInput);
1078+
if ($cleanInput !== null) {
1079+
return $cleanInput;
1080+
} else {
1081+
$err = preg_last_error_msg();
1082+
print("MagentoCLI response preg_replace() with error $err.\n");
1083+
}
1084+
}
1085+
1086+
return $input;
1087+
}
10621088
}

0 commit comments

Comments
 (0)