Skip to content

Commit

Permalink
Updating JsonCpp library to latest
Browse files Browse the repository at this point in the history
This is to resolve issues with creating a JSON value that contains the
empty string. Fixes issue #5664.
  • Loading branch information
jimevans committed Mar 22, 2018
1 parent 96c1b99 commit 7d4b038
Show file tree
Hide file tree
Showing 6 changed files with 3,982 additions and 2,028 deletions.
14 changes: 10 additions & 4 deletions cpp/iedriver/AsyncScriptExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ LRESULT AsyncScriptExecutor::OnCreate(UINT uMsg,
std::wstring serialized_args = context->serialized_script_args;
this->main_element_repository_handle_ = context->main_element_repository_handle;
if (serialized_args.size() > 0) {
Json::Reader json_reader;
json_reader.parse(StringUtilities::ToString(serialized_args), this->script_args_);
std::string parse_errors;
std::stringstream json_stream;
json_stream.str(StringUtilities::ToString(serialized_args));
Json::parseFromStream(Json::CharReaderBuilder(),
json_stream,
&this->script_args_,
&parse_errors);

if (this->script_args_.isArray()) {
this->GetElementIdList(this->script_args_);
this->script_argument_count_ = this->script_args_.size();
Expand Down Expand Up @@ -140,8 +146,8 @@ LRESULT AsyncScriptExecutor::OnGetRequiredElementList(UINT uMsg,
for (; it != this->element_id_list_.end(); ++it) {
element_id_list.append(*it);
}
Json::FastWriter writer;
std::string serialized_element_list = writer.write(element_id_list);
Json::StreamWriterBuilder writer;
std::string serialized_element_list = Json::writeString(writer, element_id_list);
std::string* return_string = reinterpret_cast<std::string*>(lParam);
*return_string = serialized_element_list.c_str();
return 0;
Expand Down
19 changes: 12 additions & 7 deletions cpp/iedriver/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ int Script::ExecuteAsync(const IECommandExecutor& command_executor,
LOG(TRACE) << "Entering Script::ExecuteAsync";
int return_code = WD_SUCCESS;

Json::FastWriter writer;
std::wstring serialized_args = StringUtilities::ToWString(writer.write(args));
Json::StreamWriterBuilder writer;
std::wstring serialized_args = StringUtilities::ToWString(Json::writeString(writer, args));
this->argument_count_ = args.size();
return_code = this->CreateAsyncScriptExecutor(command_executor.window_handle(),
serialized_args,
Expand All @@ -320,9 +320,14 @@ int Script::ExecuteAsync(const IECommandExecutor& command_executor,
WD_ASYNC_SCRIPT_GET_REQUIRED_ELEMENT_LIST,
NULL,
reinterpret_cast<LPARAM>(&required_element_list));
Json::Reader reader;
Json::Value required_elements;
reader.parse(required_element_list, required_elements);
std::string parse_errors;
std::stringstream json_stream;
json_stream.str(required_element_list);
Json::parseFromStream(Json::CharReaderBuilder(),
json_stream,
&required_elements,
&parse_errors);

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

int status_code = WD_SUCCESS;
Json::Value::iterator it = object_value.begin();
Json::Value::const_iterator it = object_value.begin();
int counter = 0;
std::string object_script = "(function(){ return function() { return {";
for (; it != object_value.end(); ++it) {
if (counter != 0) {
object_script += ",";
}
std::string counter_string = std::to_string(static_cast<long long>(counter));
std::string name = it.memberName();
std::string name = it.name();
object_script += "\"" + name + "\"" + ":arguments[" + counter_string + "]";
++counter;
}
object_script += "};}})();";

Script object_script_wrapper(this->script_engine_host_, object_script, counter);
for (it = object_value.begin(); it != object_value.end(); ++it) {
status_code = object_script_wrapper.AddArgument(element_manager, object_value[it.memberName()]);
status_code = object_script_wrapper.AddArgument(element_manager, object_value[it.name()]);
if (status_code != WD_SUCCESS) {
break;
}
Expand Down
18 changes: 12 additions & 6 deletions cpp/webdriver-server/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ void Command::Deserialize(const std::string& json) {
LOG(DEBUG) << "Raw JSON command: " << json;

Json::Value root;
Json::Reader reader;
bool successful_parse = reader.parse(json, root);
std::string parse_errors;
std::stringstream json_stream;
json_stream.str(json);
bool successful_parse = Json::parseFromStream(Json::CharReaderBuilder(),
json_stream,
&root,
&parse_errors);

if (!successful_parse) {
// report to the user the failure and their locations in the document.
LOG(WARN) << "Failed to parse configuration due "
<< reader.getFormattedErrorMessages() << std::endl
LOG(WARN) << "Failed to parse configuration due to "
<< parse_errors << std::endl
<< "JSON command: '" << json << "'";
}

Expand Down Expand Up @@ -95,8 +101,8 @@ std::string Command::Serialize() {
parameters_object[it->first] = it->second;
}
json_object["parameters"] = parameters_object;
Json::FastWriter writer;
std::string output(writer.write(json_object));
Json::StreamWriterBuilder writer;
std::string output(Json::writeString(writer, json_object));
return output;
}

Expand Down
14 changes: 10 additions & 4 deletions cpp/webdriver-server/response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ void Response::Deserialize(const std::string& json) {
LOG(TRACE) << "Entering Response::Deserialize";

Json::Value response_object;
Json::Reader reader;
reader.parse(json, response_object);
std::string parse_errors;
std::stringstream json_stream;
json_stream.str(json);
Json::parseFromStream(Json::CharReaderBuilder(),
json_stream,
&response_object,
&parse_errors);

Json::Value value_object;
if (response_object.isMember("value")) {
value_object = response_object["value"];
Expand Down Expand Up @@ -63,8 +69,8 @@ std::string Response::Serialize(void) {
} else {
json_object["value"] = this->value_;
}
Json::FastWriter writer;
std::string output(writer.write(json_object));
Json::StreamWriterBuilder writer;
std::string output(Json::writeString(writer, json_object));
return output;
}

Expand Down
Loading

0 comments on commit 7d4b038

Please sign in to comment.