Skip to content

Commit

Permalink
Slightly improve guards.
Browse files Browse the repository at this point in the history
Changelog excerpt:
- Slightly improved guards for the IPHeader class trySource method.
  • Loading branch information
Maikuolan committed Mar 21, 2024
1 parent c487650 commit b0032f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ found at:

=== Changes made since last versioned release ===

(none)
- [2024.03.21; Maikuolan]: Slightly improved guards for the IPHeader class
trySource method.

=== Version/Release 2.12.0 ===
MINOR RELEASE.
Expand Down
7 changes: 5 additions & 2 deletions src/IPHeader.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* IP header class (last modified: 2023.09.14).
* IP header class (last modified: 2024.03.21).
*
* This file is a part of the "common classes package", utilised by a number of
* packages and projects, including CIDRAM and phpMussel.
Expand Down Expand Up @@ -116,7 +116,7 @@ public function isValidIpv6(string $IP): bool
public function trySource(string $Source): string
{
/** Fail immediately if the source isn't available. */
if (!isset($_SERVER[$Source]) || strlen($_SERVER[$Source]) === 0) {
if (!isset($_SERVER[$Source]) || !is_string($_SERVER[$Source]) || strlen($_SERVER[$Source]) === 0) {
return '';
}

Expand All @@ -126,6 +126,9 @@ public function trySource(string $Source): string
/** Ensure that we're working with a string. */
if (is_array($Try)) {
$Try = array_shift($Try);
if (!is_string($Try)) {
return '';
}
}

/**
Expand Down

0 comments on commit b0032f6

Please sign in to comment.