From b703951f7a13d5ef44054b884690f0d146f27118 Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Sun, 23 Jun 2019 09:50:17 -0400 Subject: [PATCH] Handle encoded and non-encoded filenames Yaws issue 378 was due to incorrect handling of percent-encoded filenames. The fix for that in commit bc691ea led to the problem described in commit 866f363, but that commit again broke 378. To handle both issues, change yaws_api:url_decode_with_encoding/2 to employ the unicode decoding approaches from both commits. --- src/yaws_api.erl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/yaws_api.erl b/src/yaws_api.erl index 0df15df7a..a2f340e8f 100644 --- a/src/yaws_api.erl +++ b/src/yaws_api.erl @@ -796,16 +796,17 @@ url_decode_with_encoding(Path, Encoding) -> DecPath1 = case Encoding of latin1 -> DecPath; - undefined -> - case unicode:characters_to_list(list_to_binary(DecPath)) of - UTF8DecPath when is_list(UTF8DecPath) -> UTF8DecPath; - _ -> DecPath - end; _ -> - case unicode:characters_to_list(DecPath, Encoding) of + try unicode:characters_to_list(list_to_binary(DecPath)) of UTF8DecPath when is_list(UTF8DecPath) -> UTF8DecPath; _ -> DecPath - end + catch + error:badarg -> + case unicode:characters_to_list(DecPath, Encoding) of + UTF8DecPath when is_list(UTF8DecPath) -> UTF8DecPath; + _ -> DecPath + end + end end, case QS of [] -> lists:flatten(DecPath1);