From b2231990144dc23148c0df17c414aaac979bdb53 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sat, 16 Mar 2024 01:22:51 +0100 Subject: [PATCH] Align `StaticFileHandler` with Crystal's stdlib enabling Windows support --- src/kemal/static_file_handler.cr | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/kemal/static_file_handler.cr b/src/kemal/static_file_handler.cr index dbeca284..e3b17255 100644 --- a/src/kemal/static_file_handler.cr +++ b/src/kemal/static_file_handler.cr @@ -27,15 +27,10 @@ module Kemal return end - expanded_path = File.expand_path(request_path, "/") - is_dir_path = if original_path.ends_with?('/') && !expanded_path.ends_with? '/' - expanded_path = expanded_path + '/' - true - else - expanded_path.ends_with? '/' - end + request_path = Path.posix(request_path) + expanded_path = request_path.expand("/") - file_path = File.join(@public_dir, expanded_path) + file_path = @public_dir.join(expanded_path.to_kind(Path::Kind.native)) is_dir = Dir.exists?(file_path) if request_path != expanded_path