Skip to content

Commit ca0c9e6

Browse files
committed
lightningd: insert "raw" (unescaped) help messages from commands.
So if they want a \n in usage, they can have it. Signed-off-by: Rusty Russell <[email protected]>
1 parent f524f11 commit ca0c9e6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lightningd/jsonrpc.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,10 +1393,22 @@ static void setup_command_usage(struct lightningd *ld,
13931393
bool jsonrpc_command_add(struct jsonrpc *rpc, struct json_command *command,
13941394
const char *usage TAKES)
13951395
{
1396+
struct json_escape *esc;
1397+
const char *unescaped;
1398+
13961399
if (!command_add(rpc, command))
13971400
return false;
1398-
usage = tal_strdup(command, usage);
1399-
strmap_add(&rpc->usagemap, command->name, usage);
1401+
1402+
esc = json_escape_string_(tmpctx, usage, strlen(usage));
1403+
unescaped = json_escape_unescape(command, esc);
1404+
if (!unescaped)
1405+
unescaped = tal_strdup(command, usage);
1406+
else {
1407+
if (taken(usage))
1408+
tal_free(usage);
1409+
}
1410+
1411+
strmap_add(&rpc->usagemap, command->name, unescaped);
14001412
tal_add_destructor2(command, destroy_json_command, rpc);
14011413
return true;
14021414
}

0 commit comments

Comments
 (0)