diff options
author | Nicolas Noble <nnoble@google.com> | 2015-01-27 19:12:26 -0800 |
---|---|---|
committer | Nicolas Noble <nnoble@google.com> | 2015-01-27 19:12:26 -0800 |
commit | 66b5bba25bbfa5b13f527846ee35e18334e5e4ed (patch) | |
tree | 26dfa8551fc3715abb2da3111832d10af72d5630 /src | |
parent | 8c2be9bbff075ea8090dcf1332a1d94e21126524 (diff) |
Fixing a couple of minor bugs, and adding a few tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/json/json_reader.c | 9 | ||||
-rw-r--r-- | src/core/json/json_string.c | 16 | ||||
-rw-r--r-- | src/core/json/json_writer.c | 13 |
3 files changed, 22 insertions, 16 deletions
diff --git a/src/core/json/json_reader.c b/src/core/json/json_reader.c index 304da2a26b..75aa87eb03 100644 --- a/src/core/json/json_reader.c +++ b/src/core/json/json_reader.c @@ -323,6 +323,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { break; case '0': + json_reader_string_add_char(reader, c); reader->state = GRPC_JSON_STATE_VALUE_NUMBER_ZERO; break; @@ -454,7 +455,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { } break; default: - return GRPC_JSON_PARSE_ERROR; + return GRPC_JSON_INTERNAL_ERROR; } break; @@ -472,6 +473,10 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { case '8': case '9': break; + case 'e': + case 'E': + reader->state = GRPC_JSON_STATE_VALUE_NUMBER_E; + break; case '.': reader->state = GRPC_JSON_STATE_VALUE_NUMBER_DOT; break; @@ -549,6 +554,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { default: return GRPC_JSON_PARSE_ERROR; } + break; case GRPC_JSON_STATE_VALUE_NUMBER_EPM: json_reader_string_add_char(reader, c); @@ -567,6 +573,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { default: return GRPC_JSON_PARSE_ERROR; } + break; case GRPC_JSON_STATE_VALUE_TRUE_R: if (c != 'r') return GRPC_JSON_PARSE_ERROR; diff --git a/src/core/json/json_string.c b/src/core/json/json_string.c index d016f07c5a..d29e9e30e8 100644 --- a/src/core/json/json_string.c +++ b/src/core/json/json_string.c @@ -56,10 +56,10 @@ typedef struct { grpc_json* top; grpc_json* current_container; grpc_json* current_value; - char* input; - char* key; - char* string; - char* string_ptr; + gpr_uint8* input; + gpr_uint8* key; + gpr_uint8* string; + gpr_uint8* string_ptr; size_t remaining_input; } json_reader_userdata; @@ -201,7 +201,7 @@ static grpc_json* json_create_and_link(void* userdata, json->parent->child = json; } if (json->parent->type == GRPC_JSON_OBJECT) { - json->key = state->key; + json->key = (char*) state->key; } } if (!state->top) { @@ -261,13 +261,13 @@ static void json_reader_set_key(void* userdata) { static void json_reader_set_string(void* userdata) { json_reader_userdata* state = userdata; grpc_json* json = json_create_and_link(userdata, GRPC_JSON_STRING); - json->value = state->string; + json->value = (char*) state->string; } static int json_reader_set_number(void* userdata) { json_reader_userdata* state = userdata; grpc_json* json = json_create_and_link(userdata, GRPC_JSON_NUMBER); - json->value = state->string; + json->value = (char*) state->string; return 1; } @@ -312,7 +312,7 @@ grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) { state.top = state.current_container = state.current_value = NULL; state.string = state.key = NULL; - state.string_ptr = state.input = input; + state.string_ptr = state.input = (gpr_uint8*) input; state.remaining_input = size; grpc_json_reader_init(&reader, &reader_vtable, &state); diff --git a/src/core/json/json_writer.c b/src/core/json/json_writer.c index 5e7b107a03..63c86ac008 100644 --- a/src/core/json/json_writer.c +++ b/src/core/json/json_writer.c @@ -121,22 +121,21 @@ static void json_writer_escape_string(grpc_json_writer* writer, if ((c == '\\') || (c == '"')) json_writer_output_char(writer, '\\'); json_writer_output_char(writer, c); } else if (c < 32) { - json_writer_output_char(writer, '\\'); switch (c) { case '\b': - json_writer_output_char(writer, 'b'); + json_writer_output_string_with_len(writer, "\\b", 2); break; case '\f': - json_writer_output_char(writer, 'f'); + json_writer_output_string_with_len(writer, "\\f", 2); break; case '\n': - json_writer_output_char(writer, 'n'); + json_writer_output_string_with_len(writer, "\\n", 2); break; case '\r': - json_writer_output_char(writer, 'r'); + json_writer_output_string_with_len(writer, "\\r", 2); break; case '\t': - json_writer_output_char(writer, 't'); + json_writer_output_string_with_len(writer, "\\t", 2); break; default: json_writer_escape_utf16(writer, c); @@ -194,7 +193,7 @@ static void json_writer_escape_string(grpc_json_writer* writer, */ utf32 -= 0x10000; json_writer_escape_utf16(writer, 0xd800 | (utf32 >> 10)); - json_writer_escape_utf16(writer, 0xdc00 | (utf32 && 0x3ff)); + json_writer_escape_utf16(writer, 0xdc00 | (utf32 & 0x3ff)); } else { json_writer_escape_utf16(writer, utf32); } |