From 4756237d3445b941df4c8b47a60517d4c9621b7f Mon Sep 17 00:00:00 2001 From: filesite Date: Fri, 1 Apr 2022 17:13:48 +0800 Subject: [PATCH] improve realpath of links and static files --- lib/DirScanner.php | 5 ++--- test/DirScannerTest.php | 20 ++++++++++---------- test/init_test_files.sh | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lib/DirScanner.php b/lib/DirScanner.php index f1930f7..9c6fc51 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -84,7 +84,7 @@ Class DirScanner { if (in_array($field, ['title', 'snapshot'])) { $content = preg_replace('/\s/', '', $content); if ($field == 'snapshot') { - $img_realpath = "{$pathinfo['dirname']}/{$content}"; + $img_realpath = realpath("{$pathinfo['dirname']}/{$content}"); if (file_exists($img_realpath)) { $id = $this->getId($img_realpath); $fp = fopen($img_realpath, 'r'); @@ -602,8 +602,7 @@ Class DirScanner { foreach ($matches as $url) { if (preg_match('/^http(s)?:\/\//i', $url) || preg_match('/^\//i', $url)) {continue;} - $src_realpath = !preg_match('/^\.\//', $url) ? "{$pathinfo['dirname']}/{$url}" : "{$pathinfo['dirname']}/" . preg_replace('/^\.\//', '', $url); - + $src_realpath = realpath("{$pathinfo['dirname']}/{$url}"); if (file_exists($src_realpath)) { $id = $this->getId($src_realpath); $fp = fopen($src_realpath, 'r'); diff --git a/test/DirScannerTest.php b/test/DirScannerTest.php index b51de07..8c68360 100644 --- a/test/DirScannerTest.php +++ b/test/DirScannerTest.php @@ -71,24 +71,24 @@ $dirTree = $scanner->scan(__DIR__ . '/content/', 4); echo "Time cost: {$scanner->scanTimeCost} ms\n"; echo "\n"; -$readme_id = '6a8a2df95732bd046e20269707a70171'; +$readme_id = 'cd3075de9c038921184388bbdd1f08c2'; $readme_titles = $scanner->getMDTitles($readme_id); echo "Titles of MD file {$readme_id}:\n"; print_r($readme_titles); echo "\n"; echo "\n"; -$menus = $scanner->getMenus(); -echo "Directories:\n"; -print_r($menus); -echo "\n"; -echo "\n"; +//$menus = $scanner->getMenus(); +//echo "Directories:\n"; +//print_r($menus); +//echo "\n"; +//echo "\n"; -echo "Directories and files' tree:\n"; -print_r($dirTree); -echo "\n"; -echo "\n"; +//echo "Directories and files' tree:\n"; +//print_r($dirTree); +//echo "\n"; +//echo "\n"; $scanResults = $scanner->getScanResults(); diff --git a/test/init_test_files.sh b/test/init_test_files.sh index 9eaacd2..b653658 100755 --- a/test/init_test_files.sh +++ b/test/init_test_files.sh @@ -51,9 +51,34 @@ tee "Readme.md" < 古龙小说 +古龙小说2 + + +## 其它 + +其它 + +EOF + +tee "Others.md" <返回首页 EOF + mkdir -p "小说/金庸小说/" mkdir -p "小说/古龙小说/" mkdir -p "图片/图片搜索/"