Skip to content

Commit 215372a

Browse files
committed
get file ext from url with GET vars
1 parent cbb3780 commit 215372a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/FS.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ protected static function _chmod($filename, $perm, $add)
368368
*/
369369
public static function ext($path)
370370
{
371+
if (strpos($path, '?') !== false) {
372+
$path = preg_replace('#\?(.*)#', '', $path);
373+
}
374+
371375
return pathinfo($path, PATHINFO_EXTENSION);
372376
}
373377

tests/FileSystemTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ public function testExt()
315315
isSame('', FS::ext(''));
316316
isSame('', FS::ext(null));
317317
isSame('', FS::ext(false));
318+
319+
isSame('txt', FS::ext('file.txt?some_var=123456'));
320+
isSame('txt', FS::ext('file.txt?some_var=123456?invalid=param'));
321+
isSame('php', FS::ext('http://demo.jbzoo.com/sites/phones/smartfony.php?logic=and&exact=0&controller=search&option=com_zoo&task=filter&type=phone&app_id=1&Itemid=101'));
322+
isSame('', FS::ext('http://demo.jbzoo.com/sites/phones/smartfony?logic=and&exact=0&controller=search&option=com_zoo&task=filter&type=phone&app_id=1&Itemid=101'));
318323
}
319324

320325
public function testBase()
@@ -418,7 +423,6 @@ public function testGetRelative()
418423
isSame('tests/FileSystemTest.php', FS::getRelative($file, $root, '/'));
419424
isSame('tests\\FileSystemTest.php', FS::getRelative($file, $root, '\\'));
420425

421-
422426
$root = null;
423427
isSame('tests/FileSystemTest.php', FS::getRelative($file, $root, '/'));
424428
isSame('tests\\FileSystemTest.php', FS::getRelative($file, $root, '\\'));

0 commit comments

Comments
 (0)