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

Plug.Static is too sensitive for different paths writing #118

Open
rssdev10 opened this issue Sep 15, 2022 · 3 comments
Open

Plug.Static is too sensitive for different paths writing #118

rssdev10 opened this issue Sep 15, 2022 · 3 comments

Comments

@rssdev10
Copy link

Plug.Static is not providing proper errors.

using Bukdu

routes() do
    # correct way
    plug(Plug.Static, at="/static", from=normpath(joinpath(pwd(),".")))

    # wrong - not able to read from subdirs but able to get from current directory only
    # error in "from" value. For any requested file from subdir, the error 404 is generated.
    plug(Plug.Static, at="/static2", from=pwd())


    # eating symbols from the file name
    # double slash in front of "at"-value gives an exception as a result
    plug(Plug.Static, at="//static3", from=pwd())
end

Bukdu.start(8080)
@wookay
Copy link
Owner

wookay commented Sep 16, 2022

please don't use the pwd() to specify the from directory.
and what's the meaning about //?

@rssdev10
Copy link
Author

If I understand right, the from directory must contain . final symbol. That is unclear.

When the path contains a double slash then file names are interpreted without a first symbol. E.g. plug(Plug.Static, at="//static3", from=pwd()) gives an error while requesting "index.html" => /static3/ndex.html without i. Double slash might be occurring when the path was built from multiple strings with partial paths. Anyway that is not an error.

@rssdev10
Copy link
Author

Sorry, my suggestion about the . sign was wrong. When normpath() is gettign something ended by /., the result is ended by /. That is, to fix the issue with from just add inside the code normpath(joinpath(normpath(path), ".")) to avoid confusion. Internal normpath() will remove dot if present. Next joinpath will guarantee that the path contains .. And final normpath gives a path that is always ended by /.

To fix the second issue, either change the calculation of the offset, or add replace(uri_path, r"/{2,}" => '/') inside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants