From f3590c9f4aa772da7dd366ad4ecde6a7c2f66758 Mon Sep 17 00:00:00 2001 From: John Freeman Date: Fri, 9 Jun 2023 16:01:36 -0500 Subject: [PATCH 1/2] Accept all valid currency codes in API A few methods, including `book_offers`, take currency codes as parameters. The XRPL doesn't care if the letters in those codes are lowercase or uppercase, as long as they come from an alphabet defined internally. rippled doesn't care either, when they are submitted in a hex representation. When they are submitted in an ASCII string representation, rippled, but not XRPL, is more restrictive, preventing clients from interacting with some currencies already in the XRPL. This change gets rippled out of the way and lets clients submit currency codes in ASCII using the full alphabet. Fixes #4112 --- src/ripple/net/impl/RPCCall.cpp | 3 ++- src/ripple/protocol/impl/UintTypes.cpp | 10 ++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 26e56b690fa..bf360d31c18 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -121,7 +121,8 @@ class RPCParser static Json::Value jvParseCurrencyIssuer(std::string const& strCurrencyIssuer) { - static boost::regex reCurIss("\\`([[:alpha:]]{3})(?:/(.+))?\\'"); + static boost::regex reCurIss( + "\\`([][:alnum:]<>(){}[|?!@#$%^&*]{3})(?:/(.+))?\\'"); boost::smatch smMatch; diff --git a/src/ripple/protocol/impl/UintTypes.cpp b/src/ripple/protocol/impl/UintTypes.cpp index ff2644b085b..821e81238b0 100644 --- a/src/ripple/protocol/impl/UintTypes.cpp +++ b/src/ripple/protocol/impl/UintTypes.cpp @@ -93,14 +93,8 @@ to_currency(Currency& currency, std::string const& code) currency = beast::zero; - std::transform( - code.begin(), - code.end(), - currency.begin() + detail::isoCodeOffset, - [](auto c) { - return static_cast( - ::toupper(static_cast(c))); - }); + std::copy( + code.begin(), code.end(), currency.begin() + detail::isoCodeOffset); return true; } From 74d55894ac3e70a8df34d242b9819cb4ad472a6a Mon Sep 17 00:00:00 2001 From: John Freeman Date: Mon, 14 Aug 2023 10:09:26 -0500 Subject: [PATCH 2/2] Add comment explaining pattern --- src/ripple/net/impl/RPCCall.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index bf360d31c18..62392aad473 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -121,6 +121,11 @@ class RPCParser static Json::Value jvParseCurrencyIssuer(std::string const& strCurrencyIssuer) { + // Matches a sequence of 3 characters from + // `ripple::detail::isoCharSet` (the currency), + // optionally followed by a forward slash and some other characters + // (the issuer). + // https://www.boost.org/doc/libs/1_82_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html static boost::regex reCurIss( "\\`([][:alnum:]<>(){}[|?!@#$%^&*]{3})(?:/(.+))?\\'");