Skip to content

Commit

Permalink
Merge 9131791 into 4325f19
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mmy742 committed Sep 21, 2021
2 parents 4325f19 + 9131791 commit 9acccfd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Cookies.php
Expand Up @@ -170,7 +170,10 @@ protected function toHeader(string $name, array $properties): string
$result .= '; HttpOnly';
}

if (isset($properties['samesite']) && in_array(strtolower($properties['samesite']), ['lax', 'strict', 'none'], true)) {
if (
isset($properties['samesite'])
&& in_array(strtolower($properties['samesite']), ['lax', 'strict', 'none'], true)
) {
// While strtolower is needed for correct comparison, the RFC doesn't care about case
$result .= '; SameSite=' . $properties['samesite'];
}
Expand Down
15 changes: 14 additions & 1 deletion src/Uri.php
Expand Up @@ -484,7 +484,20 @@ public function __toString(): string
$query = $this->getQuery();
$fragment = $this->getFragment();

$path = '/' . ltrim($path, '/');
if ($path !== '') {
if ($path[0] !== '/') {
if ($authority !== '') {
// If the path is rootless and an authority is present, the path MUST be prefixed by "/".
$path = '/' . $path;
}
} elseif (isset($path[1]) && $path[1] === '/') {
if ($authority === '') {
// If the path is starting with more than one "/" and no authority is present,
// the starting slashes MUST be reduced to one.
$path = '/' . ltrim($path, '/');
}
}
}

return ($scheme !== '' ? $scheme . ':' : '')
. ($authority !== '' ? '//' . $authority : '')
Expand Down

0 comments on commit 9acccfd

Please sign in to comment.