ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\App\Bootstrap;
|
||||
use Magento\Framework\App\Response\Http;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
|
||||
require dirname(__DIR__, 4) . '/bootstrap.php';
|
||||
|
||||
$params = $_SERVER;
|
||||
|
||||
$bootstrap = Bootstrap::create(BP, $params);
|
||||
$objectManager = $bootstrap->getObjectManager();
|
||||
|
||||
// Load frontend event configuration because the observer is declared in etc/frontend/events.xml.
|
||||
$appState = $objectManager->get(\Magento\Framework\App\State::class);
|
||||
|
||||
try {
|
||||
$appState->setAreaCode('frontend');
|
||||
} catch (\Magento\Framework\Exception\LocalizedException $e) {
|
||||
// Area code may already be set. That's fine.
|
||||
}
|
||||
|
||||
$observer = $objectManager->get(
|
||||
\CK\LibxmlPainInTheAss\Observer\RepairMageInitAttributes::class
|
||||
);
|
||||
|
||||
echo "Observer class: " . get_class($observer) . PHP_EOL;
|
||||
|
||||
echo "============================================================\n";
|
||||
echo "CK_LibxmlPainInTheAss observer test\n";
|
||||
echo "============================================================\n";
|
||||
|
||||
echo 'PHP: ' . PHP_VERSION . PHP_EOL;
|
||||
echo 'libxml: ' . (defined('LIBXML_LOADED_VERSION') ? LIBXML_LOADED_VERSION : 'undefined') . PHP_EOL;
|
||||
|
||||
echo PHP_EOL;
|
||||
|
||||
// Create a real Magento HTTP response object.
|
||||
$response = $objectManager->create(Http::class);
|
||||
|
||||
$response->setHeader(
|
||||
'Content-Type',
|
||||
'text/html; charset=UTF-8',
|
||||
true
|
||||
);
|
||||
|
||||
/*
|
||||
* This is the exact malformed output caused by:
|
||||
*
|
||||
* libxml 2.15.3 saveHTML()
|
||||
* +
|
||||
* html_entity_decode(ENT_QUOTES)
|
||||
*/
|
||||
$input = '<html><body>' .
|
||||
'<div id="test-1" data-mage-init="{"key":"value"}"></div>' .
|
||||
'<div id="test-2" data-mage-init="{"foo":{"bar":"baz"}}"></div>' .
|
||||
'</body></html>';
|
||||
|
||||
$response->setContent($input);
|
||||
|
||||
echo "BEFORE:\n";
|
||||
echo $response->getContent() . PHP_EOL;
|
||||
echo PHP_EOL;
|
||||
|
||||
// Dispatch the exact Magento event used by the module.
|
||||
$eventManager = $objectManager->get(ManagerInterface::class);
|
||||
|
||||
$eventManager->dispatch(
|
||||
'controller_front_send_response_before',
|
||||
[
|
||||
'response' => $response,
|
||||
]
|
||||
);
|
||||
|
||||
$output = $response->getContent();
|
||||
|
||||
echo "AFTER:\n";
|
||||
echo $output . PHP_EOL;
|
||||
echo PHP_EOL;
|
||||
|
||||
// Assertions.
|
||||
echo "============================================================\n";
|
||||
echo "RESULTS\n";
|
||||
echo "============================================================\n";
|
||||
|
||||
$expected1 = '<div id="test-1" data-mage-init=\'{"key":"value"}\'></div>';
|
||||
$expected2 = '<div id="test-2" data-mage-init=\'{"foo":{"bar":"baz"}}\'></div>';
|
||||
|
||||
$isBugVersion = (defined('LIBXML_LOADED_VERSION') && (int)LIBXML_LOADED_VERSION === 21503);
|
||||
if ($isBugVersion) {
|
||||
$checks = [
|
||||
'Target libxml version detected' => true,
|
||||
'Basic data-mage-init repaired' => strpos($output, $expected1) !== false,
|
||||
'Nested JSON repaired' => strpos($output, $expected2) !== false,
|
||||
'Basic broken form removed' => strpos($output, '<div id="test-1" data-mage-init="{"key":"value"}"></div>') === false,
|
||||
'Nested broken form removed' => strpos($output, '<div id="test-2" data-mage-init="{"foo":{"bar":"baz"}}"></div>') === false,
|
||||
];
|
||||
} else {
|
||||
$checks = [
|
||||
'Non-target libxml version bypassed' => $output === $input,
|
||||
'Non-target libxml left input unchanged' => strpos($output, '<div id="test-1" data-mage-init="{"key":"value"}"></div>') !== false,
|
||||
'Nested HTML unchanged' => strpos($output, '<div id="test-2" data-mage-init="{"foo":{"bar":"baz"}}"></div>') !== false,
|
||||
];
|
||||
}
|
||||
|
||||
$failed = false;
|
||||
|
||||
foreach ($checks as $name => $passed) {
|
||||
echo str_pad($name, 35)
|
||||
. ': '
|
||||
. ($passed ? 'PASS' : 'FAIL')
|
||||
. PHP_EOL;
|
||||
|
||||
if (!$passed) {
|
||||
$failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
|
||||
if ($failed) {
|
||||
echo "OVERALL: FAIL\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "OVERALL: PASS\n";
|
||||
exit(0);
|
||||
Reference in New Issue
Block a user