aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorruanpienaar <[email protected]>2018-11-07 23:35:32 +0000
committerLoïc Hoguin <[email protected]>2019-09-05 17:40:37 +0200
commit094387a08f95c91ec6e297aa5e5786aff0ab0a65 (patch)
tree9886224e1fca527893337a31b993426bf84d4e5b /examples
parentbbf36a2ac031ff4f45df400aa27d4516a6f54c5b (diff)
downloadcowboy-094387a08f95c91ec6e297aa5e5786aff0ab0a65.tar.gz
cowboy-094387a08f95c91ec6e297aa5e5786aff0ab0a65.tar.bz2
cowboy-094387a08f95c91ec6e297aa5e5786aff0ab0a65.zip
file_server example: Fix ../ links
Amended to fix an issue with repeated path segments.
Diffstat (limited to 'examples')
-rw-r--r--examples/file_server/src/directory_h.erl8
1 files changed, 7 insertions, 1 deletions
diff --git a/examples/file_server/src/directory_h.erl b/examples/file_server/src/directory_h.erl
index 3232a7e..66e1466 100644
--- a/examples/file_server/src/directory_h.erl
+++ b/examples/file_server/src/directory_h.erl
@@ -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"].