/** * 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); }
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; }
function setEZXMLAttribute($attribute, $attributeValue, $link = false) { $contentObjectID = $attribute->attribute("contentobject_id"); $parser = new eZSimplifiedXMLInputParser($contentObjectID, false, 0, false); $attributeValue = str_replace("\r", '', $attributeValue); $attributeValue = str_replace("\n", '', $attributeValue); $attributeValue = str_replace("\t", ' ', $attributeValue); $document = $parser->process($attributeValue); if (!is_object($document)) { $cli = eZCLI::instance(); $cli->output('Error in xml parsing'); return; } $domString = eZXMLTextType::domString($document); $attribute->setAttribute('data_text', $domString); $attribute->store(); }
$dataMap = $contentObject->attribute('data_map'); $map = $mapSettings->variable('NewsletterAutomapping', $class->attribute('identifier')); foreach ($map as $objectAttribute => $typeSource) { // Check if attribute has content if (0 < strlen(trim($newsletterType->attribute($typeSource)))) { $attribute = $dataMap[$objectAttribute]; if ('ezxmltext' === $attribute->DataTypeString) { $inputData = '<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/" >'; $inputData .= '<paragraph>'; $inputData .= html_entity_decode($newsletterType->attribute($typeSource)); $inputData .= '</paragraph>'; $inputData .= '</section>'; try { $parser = new eZSimplifiedXMLInputParser($attribute->ContentObjectID); $parser->setParseLineBreaks(true); $document = $parser->process($inputData); $input = $document->saveXML(); if ($input === false) { throw new Exception(); } } catch (Exception $e) { eZDebug::writeError("Invalid XML input data.", 'view_newslettertype'); $input = ""; } } else { $input = $newsletterType->attribute($typeSource); } $attribute->setAttribute('data_text', $input); $attribute->store(); } }
private function processXmlTextData($xml, $attribute) { $parser = new eZSimplifiedXMLInputParser($this->object->attribute('id')); $parser->ParseLineBreaks = true; $xml = $parser->process($xml); $xml = eZXMLTextType::domString($xml); $urlIdArray = $parser->getUrlIDArray(); if (count($urlIdArray) > 0) { eZSimplifiedXMLInput::updateUrlObjectLinks($attribute, $urlIdArray); } return $xml; }
/** * Test for EZP-22563 * * Make sure an header without break is still parsed without any line * element. * * @link https://jira.ez.no/browse/EZP-22563 */ public function testHeaderNoBreak() { $parser = new eZSimplifiedXMLInputParser(0); $input = '<header level="1">Franz Ferdinand - Love Illumination</header>'; $dom = $parser->process($input); self::assertInstanceOf('DomDocument', $dom); $lines = $dom->getElementsByTagName('line'); $header = $dom->getElementsByTagName('header'); self::assertEquals(0, $lines->length); self::assertEquals(1, $header->length); self::assertEquals("Franz Ferdinand - Love Illumination", $header->item(0)->textContent); }
/** * Convert input to XML format used by eZ for article ingress and body * @param String $content * @return String */ protected function xmlConvert($content) { $parser = new eZSimplifiedXMLInputParser(); $parser->setParseLineBreaks(true); $document = $parser->process($content); return eZXMLTextType::domString($document); }