Skip to content

Prevent hidden root path to be ignored by --ignore-hidden-files feature#606

Merged
joseluisq merged 3 commits intostatic-web-server:masterfrom
mightyiam:hidden-base-path-not-ignored
Dec 27, 2025
Merged

Prevent hidden root path to be ignored by --ignore-hidden-files feature#606
joseluisq merged 3 commits intostatic-web-server:masterfrom
mightyiam:hidden-base-path-not-ignored

Conversation

@mightyiam
Copy link
Contributor

@mightyiam mightyiam commented Dec 26, 2025

Description

This PR fixes an issue where SWS returned 404 when serving from a hidden directory (i.e., /.root) together with the --ignore-hidden-files feature being enabled.

Server configuration

$ static-web-server -p 8788 -d .public/ --ignore-hidden-files

Before

$ curl -I http://localhost:8788
# HTTP/1.1 404 Not Found
# content-type: text/html; charset=utf-8
# content-length: 312
# accept-ranges: bytes
# vary: accept-encoding
# cache-control: max-age=86400
# date: Fri, 26 Dec 2025 14:24:54 GMT

After (expected)

$ curl -I http://localhost:8788
# HTTP/1.1 200 OK
# content-length: 639
# content-type: text/html
# accept-ranges: bytes
# last-modified: Sat, 20 Dec 2025 11:48:14 GMT
# vary: accept-encoding
# cache-control: max-age=86400
# date: Fri, 26 Dec 2025 14:27:05 GMT

Related Issue

Motivation and Context

I think that only components of the path under the base path should be considered for being hidden.
The base path is explicit and there is no point in considering its components.
Current behavior was undesirable when I was trying to make automated tests that make use of this project.
In my tests, I have created temporary base directories that happen to have a hidden component.

How Has This Been Tested?

Added a test.

Screenshots (if appropriate):

@semanticdiff-com
Copy link

semanticdiff-com bot commented Dec 26, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  src/static_files.rs  27% smaller
  tests/fixtures/.hidden-root/.hidden-file.txt Unsupported file format
  tests/fixtures/.hidden-root/foo.html  0% smaller
  tests/static_files.rs  0% smaller

@mightyiam
Copy link
Contributor Author

The test in the first commit fails before the second commit is applied.

@mightyiam mightyiam marked this pull request as ready for review December 26, 2025 04:29
@joseluisq joseluisq added v2 v2 release bugfix This is PR fixes a bug labels Dec 26, 2025
@joseluisq joseluisq changed the title hidden base path not ignored Prevent hidden root path to be ignored by --ignore-hidden-files feature Dec 26, 2025
@joseluisq
Copy link
Collaborator

Good catch.
The title and description were not clear, so I just updated them for users can get more context.

@mightyiam mightyiam force-pushed the hidden-base-path-not-ignored branch from 0864efc to b78f759 Compare December 26, 2025 15:13
@mightyiam mightyiam requested a review from joseluisq December 26, 2025 15:14
Copy link
Collaborator

@joseluisq joseluisq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@joseluisq joseluisq merged commit 1a31f00 into static-web-server:master Dec 27, 2025
29 checks passed
@joseluisq joseluisq added this to the v2.40.2 milestone Dec 27, 2025
@mightyiam mightyiam deleted the hidden-base-path-not-ignored branch December 27, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This is PR fixes a bug v2 v2 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants