common/json_escaped: new type which explicitly notes a string is already JSON.

Trivial to use as a string, but it still means you should be careful
around it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-03-26 10:38:15 +10:30
parent a077c3defb
commit d92579f627
12 changed files with 207 additions and 96 deletions

View File

@@ -1,4 +1,5 @@
#include "../json.c"
#include "../json_escaped.c"
#include <stdio.h>
/* AUTOGENERATED MOCKS START */
@@ -85,12 +86,14 @@ static void test_json_escape(void)
for (i = 1; i < 256; i++) {
char badstr[2];
struct json_result *result = new_json_result(NULL);
struct json_escaped *esc;
badstr[0] = i;
badstr[1] = 0;
json_object_start(result, NULL);
json_add_string_escape(result, "x", badstr);
esc = json_escape(NULL, badstr);
json_add_escaped_string(result, "x", take(esc));
json_object_end(result);
str = json_result_string(result);
@@ -114,4 +117,6 @@ int main(void)
test_json_tok_bitcoin_amount();
test_json_filter();
test_json_escape();
assert(!taken_any());
take_cleanup();
}