From 23749b51aa90a9f0dad8385a6a9a87401eb15354 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sat, 19 Jun 2021 19:46:10 -0400 Subject: [PATCH] Tests for path resolution --- lib/Service/Daemon.php | 5 +++-- tests/cases/Service/TestDaemon.php | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Service/Daemon.php b/lib/Service/Daemon.php index c89dea83..4dc9d36f 100644 --- a/lib/Service/Daemon.php +++ b/lib/Service/Daemon.php @@ -159,9 +159,10 @@ class Daemon { if ($cwd === false) { return false; } - $path = substr($cwd, 1)."/".$path; + $path = explode("/", substr($cwd, 1)."/".$path); + } else { + $path = explode("/", substr($path, 1)); } - $path = explode("/", substr($path, 1)); $out = []; foreach ($path as $p) { if ($p === "..") { diff --git a/tests/cases/Service/TestDaemon.php b/tests/cases/Service/TestDaemon.php index 66317dfd..b0842132 100644 --- a/tests/cases/Service/TestDaemon.php +++ b/tests/cases/Service/TestDaemon.php @@ -41,12 +41,18 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest { public function providePathResolutions(): iterable { return [ - ["/", "/home/me", "/"], - ["/.", "/home/me", "/"], - ["/..", "/home/me", "/"], - ["/run", "/home/me", "/run"], - ["/./run", "/home/me", "/run"], - ["/../run", "/home/me", "/run"], + ["/", "/home/me", "/"], + ["/.", "/home/me", "/"], + ["/..", "/home/me", "/"], + ["/run", "/home/me", "/run"], + ["/./run", "/home/me", "/run"], + ["/../run", "/home/me", "/run"], + ["/run/../run", "/home/me", "/run"], + ["/run/./run", "/home/me", "/run/run"], + ["run", "/home/me", "/home/me/run"], + ["run/..", "/home/me", "/home/me"], + [".", "/", "/"], + [".", false, false], ]; }