Skip to content

Commit eea47b3

Browse files
committed
Return 404 if folder is accessed
Fixes #19
1 parent 9c0d554 commit eea47b3

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Web frontends change log
33

44
## ?.?.? / ????-??-??
55

6+
## 3.0.1 / 2021-04-11
7+
8+
* Fixed issue #19: Raise 404 if folder is accessed - @thekid
9+
610
## 3.0.0 / 2021-04-10
711

812
* Removed deprecated *ClassesIn* replaced by `web.frontend.HandlersIn`

src/main/php/web/frontend/AssetsFrom.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function handle($request, $response) {
7171
// Check all variants in Accept-Encoding, including `*`
7272
foreach (self::accepted($request->header('Accept-Encoding', '')) as $encoding => $q) {
7373
$target= new Path($base, $path.(self::EXTENSIONS[$encoding] ?? '*'));
74-
if ($target->exists()) {
74+
if ($target->exists() && $target->isFile()) {
7575
$response->header('Vary', 'Accept-Encoding');
7676
'*' === $encoding || $response->header('Content-Encoding', $encoding);
7777

src/test/php/web/frontend/unittest/AssetsFromTest.class.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ public function returns_error_when_file_is_not_found() {
151151
Assert::equals(404, $res->status());
152152
}
153153

154+
#[Test]
155+
public function returns_error_when_folder_is_accessed() {
156+
$res= $this->serve(new AssetsFrom($this->folderWith([])), '/');
157+
158+
Assert::equals(404, $res->status());
159+
}
160+
154161
#[Test, Values([['fixture.css.gz', 'gzip'], ['fixture.css.br', 'br'], ['fixture.css.dfl', 'deflate'], ['fixture.css.bz2', 'bzip2']])]
155162
public function serves_compressed_when_gz_file_present($file, $encoding) {
156163
$files= [$file => self::COMPRESSED];

0 commit comments

Comments
 (0)