Skip to content

Commit 905ac60

Browse files
committed
Fixed Url::getdirectory
1 parent 3aa8c68 commit 905ac60

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Embed/Url.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ public function getDomain($first_level = false)
395395
*/
396396
public function getDirectory($key)
397397
{
398+
if ($key === count($this->info['path'])) {
399+
return $this->info['file'];
400+
}
401+
398402
return isset($this->info['path'][$key]) ? $this->info['path'][$key] : null;
399403
}
400404

tests/EmbedTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,14 @@ public function testUrlParser()
9999
$this->assertEquals($expected_url, $parsed_url->getUrl());
100100
}
101101
}
102+
103+
public function testUrlDirectory()
104+
{
105+
$url = new Embed\Url('http://domain.com/first//second/third');
106+
107+
$this->assertEquals('first', $url->getDirectory(0));
108+
$this->assertEquals('second', $url->getDirectory(1));
109+
$this->assertEquals('third', $url->getDirectory(2));
110+
$this->assertNull($url->getDirectory(3));
111+
}
102112
}

0 commit comments

Comments
 (0)