diff --git a/ChangeLog.md b/ChangeLog.md index ce1de13..821ec8d 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,10 @@ Web frontends change log ## ?.?.? / ????-??-?? +## 3.0.1 / 2021-04-11 + +* Fixed issue #19: Raise 404 if folder is accessed - @thekid + ## 3.0.0 / 2021-04-10 * Removed deprecated *ClassesIn* replaced by `web.frontend.HandlersIn` diff --git a/src/main/php/web/frontend/AssetsFrom.class.php b/src/main/php/web/frontend/AssetsFrom.class.php index 7705f5e..d6edc20 100755 --- a/src/main/php/web/frontend/AssetsFrom.class.php +++ b/src/main/php/web/frontend/AssetsFrom.class.php @@ -71,7 +71,7 @@ public function handle($request, $response) { // Check all variants in Accept-Encoding, including `*` foreach (self::accepted($request->header('Accept-Encoding', '')) as $encoding => $q) { $target= new Path($base, $path.(self::EXTENSIONS[$encoding] ?? '*')); - if ($target->exists()) { + if ($target->exists() && $target->isFile()) { $response->header('Vary', 'Accept-Encoding'); '*' === $encoding || $response->header('Content-Encoding', $encoding); diff --git a/src/test/php/web/frontend/unittest/AssetsFromTest.class.php b/src/test/php/web/frontend/unittest/AssetsFromTest.class.php index 29263a6..369b0bc 100755 --- a/src/test/php/web/frontend/unittest/AssetsFromTest.class.php +++ b/src/test/php/web/frontend/unittest/AssetsFromTest.class.php @@ -151,6 +151,13 @@ public function returns_error_when_file_is_not_found() { Assert::equals(404, $res->status()); } + #[Test] + public function returns_error_when_folder_is_accessed() { + $res= $this->serve(new AssetsFrom($this->folderWith([])), '/'); + + Assert::equals(404, $res->status()); + } + #[Test, Values([['fixture.css.gz', 'gzip'], ['fixture.css.br', 'br'], ['fixture.css.dfl', 'deflate'], ['fixture.css.bz2', 'bzip2']])] public function serves_compressed_when_gz_file_present($file, $encoding) { $files= [$file => self::COMPRESSED];