From 55d1ee982c22fd7189d2623ee5eed3bf48e846c3 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:49:05 +0200 Subject: [PATCH] Ignore case when converting onion addresses --- src/util.cpp | 8 +++++++- tests/src/util_tests.cpp | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 74d4a92..9d435ac 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1015,8 +1015,14 @@ hash from_onion_v3(const std::string& address) return {}; } + // Convert address to lowercase + std::string s = address; + for (char& c : s) { + c = static_cast(std::tolower(c)); + } + // Checksum validation - if (to_onion_v3(result) != address) { + if (to_onion_v3(result) != s) { LOGWARN(3, "Invalid onion address \"" << address << "\": checksum failed"); return {}; } diff --git a/tests/src/util_tests.cpp b/tests/src/util_tests.cpp index 9960864..0991724 100644 --- a/tests/src/util_tests.cpp +++ b/tests/src/util_tests.cpp @@ -221,14 +221,21 @@ TEST(util, onion) "testq4ryujfitfcxabcjde6m7uqdztdep6mzd32e4wbtqna4jyponaad.onion", "test2muitbvopcoducxb6d5bqry5dmxdatupvh34anzjdeav6xiigead.onion", "test76ais6k5t4bmap4uyl2eleh6o4g423cxuvifcoke4gtgd6pjtpqd.onion", + "TEST76ais6k5t4bmap4uyl2eleh6o4g423cxuvifcoke4gtgd6pjtpqd.onion", }; for (const std::string& address : tests) { const hash h = from_onion_v3(address); ASSERT_TRUE(!h.empty()); - const std::string s = to_onion_v3(h); - ASSERT_EQ(s, address); + const std::string s1 = to_onion_v3(h); + + std::string s2 = address; + for (char& c : s2) { + c = std::tolower(c); + } + + ASSERT_EQ(s1, s2); } ASSERT_TRUE(from_onion_v3("tooshort.onion").empty());