Skip to content

Commit

Permalink
Properly encode entities when serializing XML
Browse files Browse the repository at this point in the history
Fixes #148
  • Loading branch information
drewish committed Apr 13, 2015
1 parent 14d5ec3 commit 3c347a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Recurly PHP Client Library CHANGELOG

## Version 2.4.2 (Unreleased)

* Fixes encoding of values with ampersands [#150](https://github.com/recurly/recurly-client-php/issues/150)

## Version 2.4.1 (Feb 6th, 2015)

* Added adjustment refund support: `refund()` and `toRefundAttributes()` on `Recurly_Adjustment` [#133](https://github.com/recurly/recurly-client-php/pull/133)
* Added invoice refund supprt: `refund()` and `refundAmount()` on `Recurly_Invoice` [#133](https://github.com/recurly/recurly-client-php/pull/133)
* Added invoice refund support: `refund()` and `refundAmount()` on `Recurly_Invoice` [#133](https://github.com/recurly/recurly-client-php/pull/133)

## Version 2.4.0 (Feb 2nd, 2015)

Expand Down
4 changes: 2 additions & 2 deletions Tests/Recurly/Plan_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function testDeletePlan() {
public function testCreateXml() {
$plan = new Recurly_Plan();
$plan->plan_code = 'platinum';
$plan->name = 'Platinum Plan';
$plan->name = 'Platinum & Gold Plan';
$plan->unit_amount_in_cents->addCurrency('USD', 1500);
$plan->unit_amount_in_cents->addCurrency('EUR', 1200);
$plan->setup_fee_in_cents->addCurrency('EUR', 500);
$plan->total_billing_cycles = 6;

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<plan><plan_code>platinum</plan_code><name>Platinum Plan</name><unit_amount_in_cents><USD>1500</USD><EUR>1200</EUR></unit_amount_in_cents><setup_fee_in_cents><EUR>500</EUR></setup_fee_in_cents><total_billing_cycles>6</total_billing_cycles></plan>\n",
"<?xml version=\"1.0\"?>\n<plan><plan_code>platinum</plan_code><name>Platinum &amp; Gold Plan</name><unit_amount_in_cents><USD>1500</USD><EUR>1200</EUR></unit_amount_in_cents><setup_fee_in_cents><EUR>500</EUR></setup_fee_in_cents><total_billing_cycles>6</total_billing_cycles></plan>\n",
$plan->xml()
);
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/Recurly/Resource_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ protected function getNodeName() {
return 'mock';
}
protected function getWriteableAttributes() {
return array('date', 'bool', 'number', 'array', 'nil');
return array('date', 'bool', 'number', 'array', 'nil', 'string');
}
protected function getRequiredAttributes() {
return array('required');
Expand All @@ -26,8 +26,9 @@ public function testXml() {
'string' => 'foo',
);
$resource->nil = null;
$resource->string = "Foo & Bar";
$this->assertEquals(
"<?xml version=\"1.0\"?>\n<mock><date>2013-11-11T20:47:54+00:00</date><bool>true</bool><number>34</number><array><int>1</int><string>foo</string></array><nil nil=\"nil\"></nil></mock>\n",
"<?xml version=\"1.0\"?>\n<mock><date>2013-11-11T20:47:54+00:00</date><bool>true</bool><number>34</number><array><int>1</int><string>foo</string></array><nil nil=\"nil\"></nil><string>Foo &amp; Bar</string></mock>\n",
$resource->xml()
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/recurly/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ protected function populateXmlDoc(&$doc, &$node, &$obj, $nested = false)
} else if (is_null($val)) {
$domAttribute = $doc->createAttribute('nil');
$domAttribute->value = 'nil';
$attribute_node = $doc->createElement($key, null);
$attribute_node = $node->appendChild($doc->createElement($key));
$attribute_node->appendChild($domAttribute);
$node->appendChild($attribute_node);
} else {
if ($val instanceof DateTime) {
$val = $val->format('c');
} else if (is_bool($val)) {
$val = ($val ? 'true' : 'false');
}
$node->appendChild($doc->createElement($key, $val));
$attribute_node = $node->appendChild($doc->createElement($key));
$attribute_node->appendChild($doc->createTextNode($val));
}
}
}
Expand Down

0 comments on commit 3c347a6

Please sign in to comment.