This repository was archived by the owner on Jan 13, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 2424namespace Facebook ;
2525
2626use Facebook \Authentication \AccessToken ;
27+ use Facebook \Exceptions \FacebookSDKException ;
2728
2829class FacebookApp implements \Serializable
2930{
@@ -40,10 +41,18 @@ class FacebookApp implements \Serializable
4041 /**
4142 * @param string $id
4243 * @param string $secret
44+ *
45+ * @throws FacebookSDKException
4346 */
4447 public function __construct ($ id , $ secret )
4548 {
46- $ this ->id = $ id ;
49+ if (!is_string ($ id )
50+ // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false
51+ && !is_int ($ id )) {
52+ 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. ' );
53+ }
54+ // 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
55+ $ this ->id = (string ) $ id ;
4756 $ this ->secret = $ secret ;
4857 }
4958
Original file line number Diff line number Diff line change @@ -63,4 +63,19 @@ public function testSerialization()
6363 $ this ->assertEquals ('id ' , $ newApp ->getId ());
6464 $ this ->assertEquals ('secret ' , $ newApp ->getSecret ());
6565 }
66+
67+ /**
68+ * @expectedException \Facebook\Exceptions\FacebookSDKException
69+ */
70+ public function testOverflowIntegersWillThrow ()
71+ {
72+ new FacebookApp (PHP_INT_MAX + 1 , "foo " );
73+ }
74+
75+ public function testUnserializedIdsWillBeString ()
76+ {
77+ $ newApp = unserialize (serialize (new FacebookApp (1 , "foo " )));
78+
79+ $ this ->assertSame ('1 ' , $ newApp ->getId ());
80+ }
6681}
You can’t perform that action at this time.
0 commit comments