Skip to content

Commit

Permalink
Return 404 if folder is accessed
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
thekid committed Apr 11, 2021
1 parent 9c0d554 commit eea47b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/web/frontend/AssetsFrom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions src/test/php/web/frontend/unittest/AssetsFromTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit eea47b3

Please sign in to comment.