Browse Source

json_getnodes: escape the alias when we print it out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
4139f06780
  1. 8
      lightningd/gossip_control.c
  2. 5
      tests/test_lightningd.py

8
lightningd/gossip_control.c

@ -11,6 +11,7 @@
#include <ccan/take/take.h>
#include <ccan/tal/str/str.h>
#include <common/features.h>
#include <common/json_escaped.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <errno.h>
@ -231,15 +232,16 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
json_array_start(response, "nodes");
for (i = 0; i < tal_count(nodes); i++) {
struct json_escaped *esc;
json_object_start(response, NULL);
json_add_pubkey(response, "nodeid", &nodes[i]->nodeid);
if (nodes[i]->last_timestamp < 0) {
json_object_end(response);
continue;
}
json_add_string(response, "alias",
tal_strndup(response, (char *)nodes[i]->alias,
tal_len(nodes[i]->alias)));
esc = json_escape(NULL, (const char *)nodes[i]->alias);
json_add_escaped_string(response, "alias", take(esc));
json_add_hex(response, "color",
nodes[i]->color, ARRAY_SIZE(nodes[i]->color));
json_add_u64(response, "last_timestamp",

5
tests/test_lightningd.py

@ -2127,10 +2127,9 @@ class LightningDTests(BaseLightningDTests):
.format(l1.info['id']))
node = l1.rpc.listnodes(l1.info['id'])['nodes'][0]
# FIXME: We get this wrong!
assert not node['alias'] == weird_name
assert node['alias'] == weird_name
node = l2.rpc.listnodes(l1.info['id'])['nodes'][0]
assert not node['alias'] == weird_name
assert node['alias'] == weird_name
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1 for --dev-broadcast-interval")
def test_gossip_pruning(self):

Loading…
Cancel
Save