Skip to content

Commit ddf04d0

Browse files
committed
fixed Url::withDirectoryPosition when the position is the last
1 parent 471b7d8 commit ddf04d0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Url.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,20 @@ public function withDirectoryPosition($key, $value)
221221
{
222222
$clone = clone $this;
223223

224-
if ($key === count($clone->info['path'])) {
225-
$clone->info['file'] = $value;
224+
$pos = $clone->info['path'];
225+
$hasFile = isset($clone->info['file']);
226226

227-
return $clone;
227+
if ($hasFile) {
228+
$pos[] = $clone->info['file'];
228229
}
229230

230-
$clone->info['path'][$key] = $value;
231+
$pos[$key] = $value;
232+
233+
if ($hasFile) {
234+
$clone->info['file'] = array_pop($pos);
235+
}
236+
237+
$clone->info['path'] = $pos;
231238

232239
return $clone;
233240
}

0 commit comments

Comments
 (0)