From 219d03b8ddf6e67beac08346e77cd9983fd48c8f Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Mon, 6 Feb 2023 18:17:17 +0900 Subject: [PATCH] Fix: If PoS item code contains a /, LNUrl would not work (fix #4601) (#4602) This is caused by a weird buggy behavior from ASP.NET Core concerning path value decoding. (More information on https://github.com/dotnet/aspnetcore/issues/14170#issuecomment-533342396) This hasn't been fixed for a while, and the dotnet team keeps reporting it over and over. --- BTCPayServer/Controllers/UILNURLController.cs | 5 ++++- BTCPayServer/Extensions.cs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/UILNURLController.cs b/BTCPayServer/Controllers/UILNURLController.cs index 4269fb988..8739ccecc 100644 --- a/BTCPayServer/Controllers/UILNURLController.cs +++ b/BTCPayServer/Controllers/UILNURLController.cs @@ -265,8 +265,11 @@ namespace BTCPayServer break; } + var escapedItemId = Extensions.UnescapeBackSlashUriString(itemCode); var item = items.FirstOrDefault(item1 => - item1.Id.Equals(itemCode, StringComparison.InvariantCultureIgnoreCase)); + item1.Id.Equals(itemCode, StringComparison.InvariantCultureIgnoreCase) || + item1.Id.Equals(escapedItemId, StringComparison.InvariantCultureIgnoreCase)); + if (item is null || item.Inventory <= 0 || (item.PaymentMethods?.Any() is true && diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index d451979b6..8789ca0be 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -36,6 +36,20 @@ namespace BTCPayServer { public static class Extensions { + /// + /// Unescape Uri string for %2F + /// See details at: https://github.com/dotnet/aspnetcore/issues/14170#issuecomment-533342396 + /// + /// The Uri string. + /// Unescaped back slash Uri string. + public static string UnescapeBackSlashUriString(string uriString) + { + if (uriString == null) + { + return null; + } + return uriString.Replace("%2f", "%2F").Replace("%2F", "/"); + } public static bool IsValidEmail(this string email) { if (string.IsNullOrEmpty(email))