|
@ -67,12 +67,13 @@ static int test_json_filter(void) |
|
|
x = json_get_member(str, toks, "x"); |
|
|
x = json_get_member(str, toks, "x"); |
|
|
assert(x); |
|
|
assert(x); |
|
|
assert(x->type == JSMN_STRING); |
|
|
assert(x->type == JSMN_STRING); |
|
|
assert((x->end - x->start) == 255); |
|
|
|
|
|
|
|
|
/* There are 7 one-letter escapes, and (32-5) \uXXXX escapes. */ |
|
|
|
|
|
assert((x->end - x->start) == 255 + 7*1 + (32-5)*5); |
|
|
|
|
|
/* No control characters. */ |
|
|
for (i = x->start; i < x->end; i++) { |
|
|
for (i = x->start; i < x->end; i++) { |
|
|
assert(cisprint(str[i])); |
|
|
assert((unsigned)str[i] >= ' '); |
|
|
assert(str[i] != '\\'); |
|
|
assert((unsigned)str[i] != 127); |
|
|
assert(str[i] != '"'); |
|
|
|
|
|
assert(str[i] == '?' || str[i] == badstr[i - x->start]); |
|
|
|
|
|
} |
|
|
} |
|
|
tal_free(result); |
|
|
tal_free(result); |
|
|
return 0; |
|
|
return 0; |
|
@ -112,11 +113,44 @@ static void test_json_escape(void) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void test_json_partial(void) |
|
|
|
|
|
{ |
|
|
|
|
|
const tal_t *ctx = tal(NULL, char); |
|
|
|
|
|
|
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\")->s, "\\\\")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\\\")->s, "\\\\")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\\\\\")->s, "\\\\\\\\")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\\\\\\\")->s, "\\\\\\\\")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\n")->s, "\\n")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\n")->s, "\\n")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\\"")->s, "\\\"")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\"")->s, "\\\"")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\t")->s, "\\t")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\t")->s, "\\t")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\b")->s, "\\b")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\b")->s, "\\b")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\r")->s, "\\r")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\r")->s, "\\r")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\f")->s, "\\f")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\f")->s, "\\f")); |
|
|
|
|
|
/* You're allowed to escape / according to json.org. */ |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\/")->s, "\\/")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "/")->s, "/")); |
|
|
|
|
|
|
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\u0FFF")->s, "\\u0FFF")); |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\u0FFFx")->s, "\\u0FFFx")); |
|
|
|
|
|
|
|
|
|
|
|
/* Unknown escapes should be escaped. */ |
|
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\x")->s, "\\\\x")); |
|
|
|
|
|
tal_free(ctx); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
int main(void) |
|
|
int main(void) |
|
|
{ |
|
|
{ |
|
|
test_json_tok_bitcoin_amount(); |
|
|
test_json_tok_bitcoin_amount(); |
|
|
test_json_filter(); |
|
|
test_json_filter(); |
|
|
test_json_escape(); |
|
|
test_json_escape(); |
|
|
|
|
|
test_json_partial(); |
|
|
assert(!taken_any()); |
|
|
assert(!taken_any()); |
|
|
take_cleanup(); |
|
|
take_cleanup(); |
|
|
} |
|
|
} |
|
|