From 9210efb0510d206c3fca76abd16bf7ac4d3c5294 Mon Sep 17 00:00:00 2001 From: Mark Travis Date: Mon, 30 Jun 2014 23:51:07 +0000 Subject: [PATCH] In JSON, output unprintable currency codes as hex --- src/ripple_data/protocol/STAmount.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ripple_data/protocol/STAmount.cpp b/src/ripple_data/protocol/STAmount.cpp index c6dc584866..41610b126d 100644 --- a/src/ripple_data/protocol/STAmount.cpp +++ b/src/ripple_data/protocol/STAmount.cpp @@ -223,6 +223,14 @@ std::string STAmount::createHumanCurrency (const uint160& uCurrency) { static uint160 const sIsoBits ("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF"); + // Characters we are willing to include the ASCII representation + // of a three-letter currency code + static std::string legalASCIICurrencyCharacters = + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "<>(){}[]|?!@#$%^&*"; + if (uCurrency.isZero ()) { return SYSTEM_CURRENCY_CODE; @@ -244,7 +252,8 @@ std::string STAmount::createHumanCurrency (const uint160& uCurrency) // Specifying the system currency code using ISO-style representation // is not allowed. - if (iso != SYSTEM_CURRENCY_CODE) + if ((iso != SYSTEM_CURRENCY_CODE) && + (iso.find_first_not_of (legalASCIICurrencyCharacters) == std::string::npos)) return iso; }