function validateInput($http, $base, $contentObjectAttribute) { $contentObjectID = $contentObjectAttribute->attribute('contentobject_id'); $contentObjectAttributeID = $contentObjectAttribute->attribute('id'); $contentObjectAttributeVersion = $contentObjectAttribute->attribute('version'); if ($http->hasPostVariable($base . '_data_text_' . $contentObjectAttributeID)) { $data = $http->postVariable($base . '_data_text_' . $contentObjectAttributeID); // Set original input to a global variable $originalInput = 'originalInput_' . $contentObjectAttributeID; $GLOBALS[$originalInput] = $data; // Set input valid true to a global variable $isInputValid = 'isInputValid_' . $contentObjectAttributeID; $GLOBALS[$isInputValid] = true; $text = $data; $text = preg_replace('/\\r/', '', $text); $text = preg_replace('/\\t/', ' ', $text); // first empty paragraph $text = preg_replace('/^\\n/', '<p></p>', $text); eZDebugSetting::writeDebug('kernel-datatype-ezxmltext', $text, 'eZSimplifiedXMLInput::validateInput text'); $parser = new eZSimplifiedXMLInputParser($contentObjectID, true, eZXMLInputParser::ERROR_ALL, true); $document = $parser->process($text); if (!is_object($document)) { $GLOBALS[$isInputValid] = false; $errorMessage = implode(' ', $parser->getMessages()); $contentObjectAttribute->setValidationError($errorMessage); return eZInputValidator::STATE_INVALID; } if ($contentObjectAttribute->validateIsRequired()) { $root = $document->documentElement; if (!$root->hasChildNodes()) { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Content required')); return eZInputValidator::STATE_INVALID; } } $contentObjectAttribute->setValidationLog($parser->getMessages()); $xmlString = eZXMLTextType::domString($document); $urlIDArray = $parser->getUrlIDArray(); if (count($urlIDArray) > 0) { $this->updateUrlObjectLinks($contentObjectAttribute, $urlIDArray); } $contentObject = $contentObjectAttribute->attribute('object'); $contentObject->appendInputRelationList($parser->getRelatedObjectIDArray(), eZContentObject::RELATION_EMBED); $contentObject->appendInputRelationList($parser->getLinkedObjectIDArray(), eZContentObject::RELATION_LINK); $contentObjectAttribute->setAttribute('data_text', $xmlString); return eZInputValidator::STATE_ACCEPTED; } return eZInputValidator::STATE_ACCEPTED; }
/** * Test for issue #18149: some special characters breaks the HTML to eZXML * transformation * * @link http://issues.ez.no/18149 * @group issue18149 */ public function testIssue18149() { $parser = new eZSimplifiedXMLInputParser( 0 ); $html = 'beforeafter'; $dom = $parser->process( $html ); $this->assertInstanceOf( 'DomDocument', $dom ); $paragraphs = $dom->getElementsByTagName( 'paragraph' ); $this->assertEquals( 1, $paragraphs->length ); $this->assertEquals( 'before after', $paragraphs->item( 0 )->textContent ); $this->assertEquals( 1, count( $parser->getMessages() ) ); }
/** * Test scenario for issue #015023: <header level="-1"> generate fatal error taking a lot of server resource * * Test Outline * ------------ * 1. Parse invalid xml using eZSimplifiedXMLInputParser * 2. Make sure we get a valid DOMDocument back with content * 3. Make sure resulting xmlText string matches a valid type * * @result: Error will be thrown in parser * @expected: level should be corrected to level 1 resulting in one section tag * @link http://issues.ez.no/015023 */ public function testInvalidHeaderLevel() { $parser = new eZSimplifiedXMLInputParser(2, eZXMLInputParser::ERROR_ALL, eZXMLInputParser::ERROR_ALL, true); $document = $parser->process('<header level="-1">Fatal error test</header>'); $this->assertTrue($document instanceof DOMDocument, 'Parser error: ' . join(", ", $parser->getMessages())); $root = $document->documentElement; $this->assertTrue($root->hasChildNodes(), 'Content missing, xml document is empty'); $xmlString = eZXMLTextType::domString($document); $this->assertEquals('<?xml version="1.0" encoding="utf-8"?> <section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><section><header>Fatal error test</header></section></section> ', $xmlString); }