Skip to content

Commit 46a8cd7

Browse files
committed
robustify the handling of tags/capabilities/rules which are strings of encoded json
1 parent 946d96f commit 46a8cd7

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

nonfree/controller/PubSubListener.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,17 @@ nlohmann::json toJson(const pbmessages::NetworkChange_Network& nc, pbmessages::N
311311
out["objtype"] = "network";
312312
out["id"] = nc.network_id();
313313
out["name"] = nc.name();
314-
out["capabilities"] = OSUtils::jsonParse(nc.capabilities());
314+
315+
if (nc.has_capabilities()) {
316+
std::string caps = nc.capabilities();
317+
if (caps == "null") {
318+
out["capabilities"] = "null";
319+
}
320+
else {
321+
out["capabilities"] = OSUtils::jsonParse(caps);
322+
}
323+
out["capabilities"] = OSUtils::jsonParse(caps);
324+
}
315325
out["mtu"] = nc.mtu();
316326
out["multicastLimit"] = nc.multicast_limit();
317327
out["private"] = nc.is_private();
@@ -322,9 +332,29 @@ nlohmann::json toJson(const pbmessages::NetworkChange_Network& nc, pbmessages::N
322332
else {
323333
out["remoteTraceTarget"] = "";
324334
}
325-
out["rules"] = OSUtils::jsonParse(nc.rules());
335+
336+
if (nc.has_rules()) {
337+
std::string rules = nc.rules();
338+
if (rules == "null") {
339+
out["rules"] = "[]";
340+
}
341+
else {
342+
out["rules"] = OSUtils::jsonParse(rules);
343+
}
344+
}
326345
out["rulesSource"] = nc.rules_source();
327-
out["tags"] = OSUtils::jsonParse(nc.tags());
346+
if (nc.has_tags()) {
347+
std::string tags = nc.tags();
348+
if (tags == "[]") {
349+
out["tags"] = "[]";
350+
}
351+
else {
352+
out["tags"] = OSUtils::jsonParse(tags);
353+
}
354+
}
355+
else {
356+
out["tags"] = "[]";
357+
}
328358

329359
if (nc.has_ipv4_assign_mode()) {
330360
nlohmann::json ipv4mode;

0 commit comments

Comments
 (0)