@@ -221,6 +221,10 @@ public static function treeCopyReplace(DomNode $targetNode, DomNode $sourceNode,
221221 */
222222 public static function formatCert ($ cert , $ heads = true )
223223 {
224+ if (is_null ($ cert )) {
225+ return ;
226+ }
227+
224228 $ x509cert = str_replace (array ("\x0D" , "\r" , "\n" ), "" , $ cert );
225229 if (!empty ($ x509cert )) {
226230 $ x509cert = str_replace ('-----BEGIN CERTIFICATE----- ' , "" , $ x509cert );
@@ -245,6 +249,10 @@ public static function formatCert($cert, $heads = true)
245249 */
246250 public static function formatPrivateKey ($ key , $ heads = true )
247251 {
252+ if (is_null ($ key )) {
253+ return ;
254+ }
255+
248256 $ key = str_replace (array ("\x0D" , "\r" , "\n" ), "" , $ key );
249257 if (!empty ($ key )) {
250258 if (strpos ($ key , '-----BEGIN PRIVATE KEY----- ' ) !== false ) {
@@ -319,7 +327,12 @@ public static function redirect($url, array $parameters = array(), $stay = false
319327 * Verify that the URL matches the regex for the protocol.
320328 * By default this will check for http and https
321329 */
322- $ wrongProtocol = !preg_match (self ::$ _protocolRegex , $ url );
330+ if (isset (self ::$ _protocolRegex )) {
331+ $ protocol = self ::$ _protocolRegex ;
332+ } else {
333+ $ protocol = "" ;
334+ }
335+ $ wrongProtocol = !preg_match ($ protocol , $ url );
323336 $ url = filter_var ($ url , FILTER_VALIDATE_URL );
324337 if ($ wrongProtocol || empty ($ url )) {
325338 throw new Error (
@@ -773,6 +786,10 @@ public static function parseTime2SAML($time)
773786 */
774787 public static function parseSAML2Time ($ time )
775788 {
789+ if (empty ($ time )) {
790+ return null ;
791+ }
792+
776793 $ matches = array ();
777794
778795 /* We use a very strict regex to parse the timestamp. */
@@ -1010,7 +1027,10 @@ public static function calculateX509Fingerprint($x509cert, $alg = 'sha1')
10101027 if (strncmp ($ curData , '-----END CERTIFICATE ' , 20 ) == 0 ) {
10111028 break ;
10121029 }
1013- $ data .= trim ($ curData );
1030+ if (isset ($ curData )) {
1031+ $ curData = trim ($ curData );
1032+ }
1033+ $ data .= $ curData ;
10141034 }
10151035 }
10161036
@@ -1043,6 +1063,9 @@ public static function calculateX509Fingerprint($x509cert, $alg = 'sha1')
10431063 */
10441064 public static function formatFingerPrint ($ fingerprint )
10451065 {
1066+ if (is_null ($ fingerprint )) {
1067+ return ;
1068+ }
10461069 $ formatedFingerprint = str_replace (': ' , '' , $ fingerprint );
10471070 $ formatedFingerprint = strtolower ($ formatedFingerprint );
10481071 return $ formatedFingerprint ;
0 commit comments