Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure values are UTF-8 encoded in POST bodies (fixes #27)

  • Loading branch information...
commit 292ab8bdcd4f7865ee3f41ff63277a3a5186454f 1 parent 63890fe
@ebroder ebroder authored
Showing with 12 additions and 2 deletions.
  1. +2 −2 lib/Stripe/ApiRequestor.php
  2. +10 −0 test/Stripe/ApiRequestorTest.php
View
4 lib/Stripe/ApiRequestor.php
@@ -26,7 +26,7 @@ public static function utf8($value)
private static function _encodeObjects($d)
{
if ($d instanceof Stripe_ApiResource) {
- return $d->id;
+ return self::utf8($d->id);
} else if ($d === true) {
return 'true';
} else if ($d === false) {
@@ -37,7 +37,7 @@ private static function _encodeObjects($d)
$res[$k] = self::_encodeObjects($v);
return $res;
} else {
- return $d;
+ return self::utf8($d);
}
}
View
10 test/Stripe/ApiRequestorTest.php
@@ -49,6 +49,16 @@ public function testEncodeObjects()
$a = array('customer' => new Stripe_Customer('abcd'));
$enc = $method->invoke(null, $a);
$this->assertEqual($enc, array('customer' => 'abcd'));
+
+ // Preserves UTF-8
+ $v = array('customer' => "");
+ $enc = $method->invoke(null, $v);
+ $this->assertEqual($enc, $v);
+
+ // Encodes latin-1 -> UTF-8
+ $v = array('customer' => "\xe9");
+ $enc = $method->invoke(null, $v);
+ $this->assertEqual($enc, array('customer' => "\xc3\xa9"));
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.