From 40cd54e0ec980b9049ea5910187b4ac4802388ba Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Fri, 22 Nov 2013 17:34:39 -0200 Subject: [PATCH] use utf8 for text json strings. only a few characters need to be escaped per json rfc spec. escaping everything was causing problem with browsers. --- src/bitcoinrpc.cpp | 4 ++-- src/json/json_spirit_writer_template.h | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 87d1777a..44a634dc 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -993,9 +993,9 @@ void ServiceConnection(AcceptedConnection *conn) std::vector file_data; if( load_file( fname.c_str(), file_data) == 0 ) { std::string str(file_data.data(), file_data.size()); - const char *contentType = "text/html"; + const char *contentType = "text/html; charset=utf-8"; if( strURI.find(".js") != std::string::npos ) - contentType = "text/javascript"; + contentType = "text/javascript; charset=utf-8"; if( strURI.find(".css") != std::string::npos ) contentType = "text/css"; if( strURI.find(".png") != std::string::npos ) diff --git a/src/json/json_spirit_writer_template.h b/src/json/json_spirit_writer_template.h index 28c49ddc..1568c2b7 100644 --- a/src/json/json_spirit_writer_template.h +++ b/src/json/json_spirit_writer_template.h @@ -75,6 +75,7 @@ namespace json_spirit if( add_esc_char( c, result ) ) continue; + /* const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c ); if( iswprint( unsigned_c ) ) @@ -85,6 +86,14 @@ namespace json_spirit { result += non_printable_to_string< String_type >( unsigned_c ); } + */ + // [MF] twister uses utf8 strings (and not any sort of wide char). + // only control characters need to be escaped, per JSON RFC spec. + if( c >=0 && c <= 0x1f ) { + result += non_printable_to_string< String_type >( c ); + } else { + result += c; + } } return result;