Skip to content

Commit 7d4b038

Browse files
committed
Updating JsonCpp library to latest
This is to resolve issues with creating a JSON value that contains the empty string. Fixes issue #5664.
1 parent 96c1b99 commit 7d4b038

File tree

6 files changed

+3982
-2028
lines changed

6 files changed

+3982
-2028
lines changed

cpp/iedriver/AsyncScriptExecutor.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ LRESULT AsyncScriptExecutor::OnCreate(UINT uMsg,
5151
std::wstring serialized_args = context->serialized_script_args;
5252
this->main_element_repository_handle_ = context->main_element_repository_handle;
5353
if (serialized_args.size() > 0) {
54-
Json::Reader json_reader;
55-
json_reader.parse(StringUtilities::ToString(serialized_args), this->script_args_);
54+
std::string parse_errors;
55+
std::stringstream json_stream;
56+
json_stream.str(StringUtilities::ToString(serialized_args));
57+
Json::parseFromStream(Json::CharReaderBuilder(),
58+
json_stream,
59+
&this->script_args_,
60+
&parse_errors);
61+
5662
if (this->script_args_.isArray()) {
5763
this->GetElementIdList(this->script_args_);
5864
this->script_argument_count_ = this->script_args_.size();
@@ -140,8 +146,8 @@ LRESULT AsyncScriptExecutor::OnGetRequiredElementList(UINT uMsg,
140146
for (; it != this->element_id_list_.end(); ++it) {
141147
element_id_list.append(*it);
142148
}
143-
Json::FastWriter writer;
144-
std::string serialized_element_list = writer.write(element_id_list);
149+
Json::StreamWriterBuilder writer;
150+
std::string serialized_element_list = Json::writeString(writer, element_id_list);
145151
std::string* return_string = reinterpret_cast<std::string*>(lParam);
146152
*return_string = serialized_element_list.c_str();
147153
return 0;

cpp/iedriver/Script.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ int Script::ExecuteAsync(const IECommandExecutor& command_executor,
295295
LOG(TRACE) << "Entering Script::ExecuteAsync";
296296
int return_code = WD_SUCCESS;
297297

298-
Json::FastWriter writer;
299-
std::wstring serialized_args = StringUtilities::ToWString(writer.write(args));
298+
Json::StreamWriterBuilder writer;
299+
std::wstring serialized_args = StringUtilities::ToWString(Json::writeString(writer, args));
300300
this->argument_count_ = args.size();
301301
return_code = this->CreateAsyncScriptExecutor(command_executor.window_handle(),
302302
serialized_args,
@@ -320,9 +320,14 @@ int Script::ExecuteAsync(const IECommandExecutor& command_executor,
320320
WD_ASYNC_SCRIPT_GET_REQUIRED_ELEMENT_LIST,
321321
NULL,
322322
reinterpret_cast<LPARAM>(&required_element_list));
323-
Json::Reader reader;
324323
Json::Value required_elements;
325-
reader.parse(required_element_list, required_elements);
324+
std::string parse_errors;
325+
std::stringstream json_stream;
326+
json_stream.str(required_element_list);
327+
Json::parseFromStream(Json::CharReaderBuilder(),
328+
json_stream,
329+
&required_elements,
330+
&parse_errors);
326331

327332
for (Json::UInt i = 0; i < required_elements.size(); ++i) {
328333
std::string element_id = required_elements[i].asString();
@@ -693,23 +698,23 @@ int Script::WalkObject(IElementManager* element_manager,
693698
LOG(TRACE) << "Entering Script::WalkObject";
694699

695700
int status_code = WD_SUCCESS;
696-
Json::Value::iterator it = object_value.begin();
701+
Json::Value::const_iterator it = object_value.begin();
697702
int counter = 0;
698703
std::string object_script = "(function(){ return function() { return {";
699704
for (; it != object_value.end(); ++it) {
700705
if (counter != 0) {
701706
object_script += ",";
702707
}
703708
std::string counter_string = std::to_string(static_cast<long long>(counter));
704-
std::string name = it.memberName();
709+
std::string name = it.name();
705710
object_script += "\"" + name + "\"" + ":arguments[" + counter_string + "]";
706711
++counter;
707712
}
708713
object_script += "};}})();";
709714

710715
Script object_script_wrapper(this->script_engine_host_, object_script, counter);
711716
for (it = object_value.begin(); it != object_value.end(); ++it) {
712-
status_code = object_script_wrapper.AddArgument(element_manager, object_value[it.memberName()]);
717+
status_code = object_script_wrapper.AddArgument(element_manager, object_value[it.name()]);
713718
if (status_code != WD_SUCCESS) {
714719
break;
715720
}

cpp/webdriver-server/command.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ void Command::Deserialize(const std::string& json) {
3636
LOG(DEBUG) << "Raw JSON command: " << json;
3737

3838
Json::Value root;
39-
Json::Reader reader;
40-
bool successful_parse = reader.parse(json, root);
39+
std::string parse_errors;
40+
std::stringstream json_stream;
41+
json_stream.str(json);
42+
bool successful_parse = Json::parseFromStream(Json::CharReaderBuilder(),
43+
json_stream,
44+
&root,
45+
&parse_errors);
46+
4147
if (!successful_parse) {
4248
// report to the user the failure and their locations in the document.
43-
LOG(WARN) << "Failed to parse configuration due "
44-
<< reader.getFormattedErrorMessages() << std::endl
49+
LOG(WARN) << "Failed to parse configuration due to "
50+
<< parse_errors << std::endl
4551
<< "JSON command: '" << json << "'";
4652
}
4753

@@ -95,8 +101,8 @@ std::string Command::Serialize() {
95101
parameters_object[it->first] = it->second;
96102
}
97103
json_object["parameters"] = parameters_object;
98-
Json::FastWriter writer;
99-
std::string output(writer.write(json_object));
104+
Json::StreamWriterBuilder writer;
105+
std::string output(Json::writeString(writer, json_object));
100106
return output;
101107
}
102108

cpp/webdriver-server/response.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ void Response::Deserialize(const std::string& json) {
3030
LOG(TRACE) << "Entering Response::Deserialize";
3131

3232
Json::Value response_object;
33-
Json::Reader reader;
34-
reader.parse(json, response_object);
33+
std::string parse_errors;
34+
std::stringstream json_stream;
35+
json_stream.str(json);
36+
Json::parseFromStream(Json::CharReaderBuilder(),
37+
json_stream,
38+
&response_object,
39+
&parse_errors);
40+
3541
Json::Value value_object;
3642
if (response_object.isMember("value")) {
3743
value_object = response_object["value"];
@@ -63,8 +69,8 @@ std::string Response::Serialize(void) {
6369
} else {
6470
json_object["value"] = this->value_;
6571
}
66-
Json::FastWriter writer;
67-
std::string output(writer.write(json_object));
72+
Json::StreamWriterBuilder writer;
73+
std::string output(Json::writeString(writer, json_object));
6874
return output;
6975
}
7076

0 commit comments

Comments
 (0)