[asterisk-commits] json: Check party id name, number, subaddresses for UTF-8. (asterisk[certified/13.8])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Oct 14 15:13:46 CDT 2016
Joshua Colp has submitted this change and it was merged.
Change subject: json: Check party id name, number, subaddresses for UTF-8.
......................................................................
json: Check party id name, number, subaddresses for UTF-8.
* Updated unit test as ast_json_name_number() is now NULL tolerant.
ASTERISK-26466 #close
Reported by: Richard Mudgett
Change-Id: I7d4e14194f8f81f24a1dc34d1b8602c0950265a6
---
M main/json.c
M tests/test_json.c
2 files changed, 36 insertions(+), 23 deletions(-)
Approvals:
George Joseph: Looks good to me, approved
Joshua Colp: Looks good to me, but someone else must approve; Verified
diff --git a/main/json.c b/main/json.c
index 78a47cd..9f42f0a 100644
--- a/main/json.c
+++ b/main/json.c
@@ -842,16 +842,16 @@
struct ast_json *ast_json_name_number(const char *name, const char *number)
{
return ast_json_pack("{s: s, s: s}",
- "name", name,
- "number", number);
+ "name", AST_JSON_UTF8_VALIDATE(name),
+ "number", AST_JSON_UTF8_VALIDATE(number));
}
struct ast_json *ast_json_dialplan_cep(const char *context, const char *exten, int priority)
{
return ast_json_pack("{s: o, s: o, s: o}",
- "context", context ? ast_json_string_create(context) : ast_json_null(),
- "exten", exten ? ast_json_string_create(exten) : ast_json_null(),
- "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
+ "context", context ? ast_json_string_create(context) : ast_json_null(),
+ "exten", exten ? ast_json_string_create(exten) : ast_json_null(),
+ "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
}
struct ast_json *ast_json_timeval(const struct timeval tv, const char *zone)
@@ -942,7 +942,7 @@
return NULL;
}
return ast_json_pack("{s: s, s: i, s: i, s: s}",
- "number", number->str,
+ "number", AST_JSON_UTF8_VALIDATE(number->str),
"plan", number->plan,
"presentation", number->presentation,
"presentation_txt", ast_describe_caller_presentation(number->presentation));
@@ -954,7 +954,7 @@
return NULL;
}
return ast_json_pack("{s: s, s: s, s: i, s: s}",
- "name", name->str,
+ "name", AST_JSON_UTF8_VALIDATE(name->str),
"character_set", ast_party_name_charset_describe(name->char_set),
"presentation", name->presentation,
"presentation_txt", ast_describe_caller_presentation(name->presentation));
@@ -966,7 +966,7 @@
return NULL;
}
return ast_json_pack("{s: s, s: i, s: b}",
- "subaddress", subaddress->str,
+ "subaddress", AST_JSON_UTF8_VALIDATE(subaddress->str),
"type", subaddress->type,
"odd", subaddress->odd_even_indicator);
}
@@ -986,17 +986,20 @@
}
/* Party number */
- if (party->number.valid && ast_json_object_set(json_party_id, "number", json_party_number(&party->number))) {
+ if (party->number.valid
+ && ast_json_object_set(json_party_id, "number", json_party_number(&party->number))) {
return NULL;
}
/* Party name */
- if (party->name.valid && ast_json_object_set(json_party_id, "name", json_party_name(&party->name))) {
+ if (party->name.valid
+ && ast_json_object_set(json_party_id, "name", json_party_name(&party->name))) {
return NULL;
}
/* Party subaddress */
- if (party->subaddress.valid && ast_json_object_set(json_party_id, "subaddress", json_party_subaddress(&party->subaddress))) {
+ if (party->subaddress.valid
+ && ast_json_object_set(json_party_id, "subaddress", json_party_subaddress(&party->subaddress))) {
return NULL;
}
diff --git a/tests/test_json.c b/tests/test_json.c
index 9d624cd..206bd8a 100644
--- a/tests/test_json.c
+++ b/tests/test_json.c
@@ -1597,11 +1597,26 @@
return AST_TEST_PASS;
}
+static int test_name_number(const char *name, const char *number)
+{
+ int res;
+ struct ast_json *uut;
+ struct ast_json *expected;
+
+ expected = ast_json_pack("{s: s, s: s}",
+ "name", name ?: "",
+ "number", number ?: "");
+ uut = ast_json_name_number(name, number);
+
+ res = ast_json_equal(expected, uut);
+
+ ast_json_unref(expected);
+ ast_json_unref(uut);
+ return res;
+}
+
AST_TEST_DEFINE(json_test_name_number)
{
- RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
- RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
-
switch (cmd) {
case TEST_INIT:
info->name = "name_number";
@@ -1613,15 +1628,10 @@
break;
}
- ast_test_validate(test, NULL == ast_json_name_number("name", NULL));
- ast_test_validate(test, NULL == ast_json_name_number(NULL, "1234"));
- ast_test_validate(test, NULL == ast_json_name_number(NULL, NULL));
-
- expected = ast_json_pack("{s: s, s: s}",
- "name", "Jenny",
- "number", "867-5309");
- uut = ast_json_name_number("Jenny", "867-5309");
- ast_test_validate(test, ast_json_equal(expected, uut));
+ ast_test_validate(test, test_name_number("name", NULL));
+ ast_test_validate(test, test_name_number(NULL, "1234"));
+ ast_test_validate(test, test_name_number(NULL, NULL));
+ ast_test_validate(test, test_name_number("Jenny", "867-5309"));
return AST_TEST_PASS;
}
--
To view, visit https://gerrit.asterisk.org/4105
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7d4e14194f8f81f24a1dc34d1b8602c0950265a6
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.8
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
More information about the asterisk-commits
mailing list