Browse Source

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.
miguelfreitas
Miguel Freitas 11 years ago
parent
commit
40cd54e0ec
  1. 4
      src/bitcoinrpc.cpp
  2. 9
      src/json/json_spirit_writer_template.h

4
src/bitcoinrpc.cpp

@ -993,9 +993,9 @@ void ServiceConnection(AcceptedConnection *conn) @@ -993,9 +993,9 @@ void ServiceConnection(AcceptedConnection *conn)
std::vector<char> 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 )

9
src/json/json_spirit_writer_template.h

@ -75,6 +75,7 @@ namespace json_spirit @@ -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 @@ -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;

Loading…
Cancel
Save