Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to deal with malformed UTF-8 in file names #374

Merged
merged 2 commits into from
Apr 28, 2024

Conversation

palant
Copy link
Contributor

@palant palant commented Apr 28, 2024

Description

This streamlines the logic in directory listings as discussed. It also makes sure to operate with file names as OsString, allowing for invalid Unicode in file names. The (potentially lossy) conversion to string only happens when the name needs to be displayed. Quite a few unnecessary error conditions got removed as a side-effect.

Something to consider would be enabling serialization of the uri field in JSON. Since the name field might have lost information, there is currently no reliable way to deduce the file’s URL from the JSON data.

Related Issue

#371

How Has This Been Tested?

On the Linux command line I did:

echo test > `echo -e "file\x80.txt"`
mkdir `echo -e "dir\x80.txt"`
echo test > `echo -e "dir\x80/test.txt"`

I verified that both the directory and the file show up in the listing (with the Unicode placeholder showing up for \x80) and both can be opened. The file text.txt in the directory can be opened as well.

As to Windows, I’m not sure that creating a file with a non-Unicode name is even possible. I did verify that the fallback employed there works on Linux (for properly encoded file names) but I didn’t perform any testing on Windows.

Copy link

semanticdiff-com bot commented Apr 28, 2024

Review changes with SemanticDiff.

Analyzed 2 of 2 files.

Overall, the semantic diff is 22% smaller than the GitHub diff.

Filename Status
✔️ src/directory_listing.rs 22.1% smaller
✔️ src/file_path.rs 18.64% smaller

@palant
Copy link
Contributor Author

palant commented Apr 28, 2024

This seems to have improved the performance of large directory slightly, around 2%.

@joseluisq joseluisq added v2 v2 release bugfix This is PR fixes a bug labels Apr 28, 2024
@palant
Copy link
Contributor Author

palant commented Apr 28, 2024

Another observation: with this change symlinks show up with the size of the linked file which is correct IMHO. Previously it was the size of the symlink which makes little sense given that the file is otherwise not indicated as a symlink.

The MIME type is being derived from the file name of the symlink however, not the linked file. I wonder whether that is the right thing to do here.

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.

Just minor comments to check.

src/directory_listing.rs Show resolved Hide resolved
src/directory_listing.rs Show resolved Hide resolved
src/file_path.rs Show resolved Hide resolved
@joseluisq
Copy link
Collaborator

The MIME type is being derived from the file name of the symlink however, not the linked file. I wonder whether that is the right thing to do here.

Good question, yeah the symlink name could differ from the actual linked file but I do not if we should follow the symlink to that point.
Maybe we could come up with some idea of how other web servers handle this.
But, honestly symlink following should have been an opt-in feature and disabled by default.

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.

No need to delay the PR.
Thanks!

@joseluisq joseluisq merged commit 114862a into static-web-server:master Apr 28, 2024
36 checks passed
@joseluisq joseluisq added this to the v2.30.0 milestone Apr 28, 2024
@palant palant deleted the dirlisting-improvements branch April 28, 2024 21:00
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.

None yet

2 participants