Skip to content

Commit

Permalink
Add consistency check
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-scott committed Apr 3, 2016
1 parent c7e26a2 commit 1115ffa
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/byte_safe_strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ function RandomCompat_substr($binary_string, $start, $length = null)
);
}

// Consistency with PHP's behavior
if ($start === RandomCompat_strlen($binary_string) && $length === 0) {
return '';
}
if ($start > RandomCompat_strlen($binary_string)) {
return false;
}

return mb_substr($binary_string, $start, $length, '8bit');
}

Expand Down

0 comments on commit 1115ffa

Please sign in to comment.