From 6cfb1dbbddcae70f4db5c98f813edcb8f5e5d97a Mon Sep 17 00:00:00 2001 From: SammyK Date: Wed, 10 Feb 2016 18:26:06 -0600 Subject: [PATCH] Add better error checking for app IDs as int when greater than PHP_INT_MAX --- src/Facebook/FacebookApp.php | 11 ++++++++++- tests/FacebookAppTest.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Facebook/FacebookApp.php b/src/Facebook/FacebookApp.php index 84956ce98..2f4da1be8 100644 --- a/src/Facebook/FacebookApp.php +++ b/src/Facebook/FacebookApp.php @@ -24,6 +24,7 @@ namespace Facebook; use Facebook\Authentication\AccessToken; +use Facebook\Exceptions\FacebookSDKException; class FacebookApp implements \Serializable { @@ -40,10 +41,18 @@ class FacebookApp implements \Serializable /** * @param string $id * @param string $secret + * + * @throws FacebookSDKException */ public function __construct($id, $secret) { - $this->id = $id; + if (!is_string($id) + // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false + && !is_int($id)) { + throw new FacebookSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.'); + } + // We cast as a string in case a valid int was set on a 64-bit system and this is unserialised on a 32-bit system + $this->id = (string) $id; $this->secret = $secret; } diff --git a/tests/FacebookAppTest.php b/tests/FacebookAppTest.php index d1b453dbc..257047a81 100644 --- a/tests/FacebookAppTest.php +++ b/tests/FacebookAppTest.php @@ -63,4 +63,19 @@ public function testSerialization() $this->assertEquals('id', $newApp->getId()); $this->assertEquals('secret', $newApp->getSecret()); } + + /** + * @expectedException \Facebook\Exceptions\FacebookSDKException + */ + public function testOverflowIntegersWillThrow() + { + new FacebookApp(PHP_INT_MAX + 1, "foo"); + } + + public function testUnserializedIdsWillBeString() + { + $newApp = unserialize(serialize(new FacebookApp(1, "foo"))); + + $this->assertSame('1', $newApp->getId()); + } }