0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 04:10:24 +00:00

file_server example: Fix ../ links

Amended to fix an issue with repeated path segments.
This commit is contained in:
ruanpienaar 2018-11-07 23:35:32 +00:00 committed by Loïc Hoguin
parent bbf36a2ac0
commit 094387a08f
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -41,7 +41,13 @@ list_html(Req, {Path, Fs}) ->
"<body>">>, Body, <<"</body></html>\n">>],
{HTML, Req, Path}.
links(<<>>, "..") ->
"<a href='/..'>..</a><br>\n";
links(Prefix, "..") ->
Tokens = string:tokens(binary_to_list(Prefix), "/"),
Back = lists:join("/", lists:reverse(tl(lists:reverse(Tokens)))),
["<a href='/../", Back, "'>..</a><br>\n"];
links(<<>>, File) ->
["<a href='/", File, "'>", File, "</a><br>\n"];
links(Prefix, File) ->
["<a href='/", Prefix, $/, File, "'>", File, "</a><br>\n"].
["<a href='/", Prefix, File, "'>", File, "</a><br>\n"].