Browse files

Fixing implementation of Media::encode. Default handler values for 'e…

…ncode' is false,

isset returns true on this causing encode to attempt to run against it. Updating !isset to empty
to properly trigger for this scenario.
  • Loading branch information...
1 parent e8a41f0 commit ddf13ab68cf680d3332bbffa3226b2c31bece465 @Howard3 Howard3 committed Mar 14, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 net/http/Media.php
  2. +6 −0 tests/cases/net/http/MediaTest.php
View
2 net/http/Media.php
@@ -653,7 +653,7 @@ public static function encode($handler, $data, &$response = null) {
$handler = $self::invokeMethod('_handlers', array($handler));
}
- if (!$handler || !isset($handler['encode'])) {
+ if (!$handler || empty($handler['encode'])) {
return null;
}
View
6 tests/cases/net/http/MediaTest.php
@@ -522,6 +522,12 @@ public function testEncodeRecordSet() {
$this->assertEqual($json, Media::encode(array('encode' => 'json_encode'), $data));
}
+ public function testEncodeNotCallable() {
+ $data = array('foo' => 'bar');
+ $result = Media::encode(array('encode' => false), $data);
+ $this->assertNull($result);
+ }
+
/**
* Tests that calling `Media::type()` to retrieve the details of a type that is aliased to
* another type, automatically resolves to the settings of the type being pointed at.

1 comment on commit ddf13ab

@rmarscher

Thanks for incorporating this, Howard3.

Please sign in to comment.