Skip to content

Commit

Permalink
XML destination - handle special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Hall committed Mar 2, 2018
1 parent 0c5cb13 commit a44453f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Objects/Destinations/XMLDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function putDataRows(array $dataRows)
$dataRowDomElement = $this->rootElement->appendChild(new DOMElement($this->rowElementName));

foreach ($dataItems as $dataItem) {
$dataItemDomElement = new DOMElement($dataItem->fieldName, $dataItem->value);
$dataItemDomElement = new DOMElement($dataItem->fieldName, htmlspecialchars($dataItem->value));
$dataRowDomElement->appendChild($dataItemDomElement);
}
}
Expand Down
9 changes: 7 additions & 2 deletions tests/Unit/XMLDestinationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ private function createDataRows()
$dataRow->addDataItem(new DataItem('value', $faker->randomNumber));
$dataRows[] = $dataRow;

$dataRow = new DataRow();
$dataRow->addDataItem(new DataItem('name', 'special_characters_test_&<>'));
$dataRow->addDataItem(new DataItem('value', $faker->randomNumber));
$dataRows[] = $dataRow;

return $dataRows;
}

Expand All @@ -33,9 +38,9 @@ private function getExpectedFileContent(array $dataRows)

foreach ($dataRows as $dataRow) {
$expectedFileContent .= '<dataRow><name>';
$expectedFileContent .= $dataRow->getDataItemByFieldName('name')->value;
$expectedFileContent .= htmlspecialchars($dataRow->getDataItemByFieldName('name')->value);
$expectedFileContent .= '</name><value>';
$expectedFileContent .= $dataRow->getDataItemByFieldName('value')->value;
$expectedFileContent .= htmlspecialchars($dataRow->getDataItemByFieldName('value')->value);
$expectedFileContent .= '</value></dataRow>';
}

Expand Down

0 comments on commit a44453f

Please sign in to comment.