summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2015-06-01 11:45:30 -0500
committerKevin Harwell <kharwell@digium.com>2015-06-03 14:03:18 -0500
commitf5d5aa67dcdc274770c47b1a801a449fb83c2f79 (patch)
treec751e639227e97ef718524eb482ae1acf4ed28bf /tests
parentbc70904c053ccc3c14d2b2f87ee81b5e8ffadbbb (diff)
AMI: Escape string values.
So this issue is a bit complicated. Since it is possible to pass values to AMI that contain a '\r\n' (or other similar sequences) these values need to be escaped. One way to solve this is to escape the values and then pass the escaped values to the AMI variable parameter string building function. However, this puts the onus on the pre-build function to escape all string values. This potentially requires a fair amount of changes along with a lot of string allocations/freeing for all values. Surely there is a way to push this complexity down a level into the string building function itself? This of course is possible, but ends up requiring a way to distinguish between strings that need to be escaped and those that don't. The best way to handle this is by introducing a new format specifier in the format string. For instance a %s (no escape) and %S (escape). However, that is a bit weird and unexpected. So faced with those possibilities this patch implements a limited version of the first option. Instead of attempting to escape all string values this patch only escapes those values that make sense. This approach limits the number of changes and doesn't suffer from the odd format specifier problem. ASTERISK-24934 #close Reported by: warren smith Change-Id: Ib55a5b84fe0481b0f2caaaab68c566f392c0aac0
Diffstat (limited to 'tests')
-rw-r--r--tests/test_strings.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_strings.c b/tests/test_strings.c
index 4321d4a03..ab65037ee 100644
--- a/tests/test_strings.c
+++ b/tests/test_strings.c
@@ -455,6 +455,38 @@ AST_TEST_DEFINE(escape_semicolons_test)
return AST_TEST_PASS;
}
+AST_TEST_DEFINE(escape_test)
+{
+ char buf[128];
+
+#define TEST_ESCAPE(s, to_escape, expected) \
+ !strcmp(ast_escape(buf, s, sizeof(buf) / sizeof(char), to_escape), expected)
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "escape";
+ info->category = "/main/strings/";
+ info->summary = "Test ast_escape";
+ info->description = "Test escaping values in a string";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ ast_test_validate(test, TEST_ESCAPE("null escape", NULL, "null escape"));
+ ast_test_validate(test, TEST_ESCAPE("no matching escape", "Z", "no matching escape"));
+ ast_test_validate(test, TEST_ESCAPE("escape Z", "Z", "escape \\Z"));
+ ast_test_validate(test, TEST_ESCAPE("Z", "Z", "\\Z"));
+ ast_test_validate(test, TEST_ESCAPE(";;", ";;", "\\;\\;"));
+ ast_test_validate(test, TEST_ESCAPE("escape \n", "\n", "escape \\n"));
+ ast_test_validate(test, TEST_ESCAPE("escape \n again \n", "\n", "escape \\n again \\n"));
+
+ ast_test_validate(test, !strcmp(ast_escape_c(buf, "escape \a\b\f\n\r\t\v\\\'\"\?",
+ sizeof(buf) / sizeof(char)),
+ "escape \\a\\b\\f\\n\\r\\t\\v\\\\\\\'\\\"\\?"));
+ return AST_TEST_PASS;
+}
+
static int unload_module(void)
{
AST_TEST_UNREGISTER(str_test);
@@ -462,6 +494,7 @@ static int unload_module(void)
AST_TEST_UNREGISTER(ends_with_test);
AST_TEST_UNREGISTER(strsep_test);
AST_TEST_UNREGISTER(escape_semicolons_test);
+ AST_TEST_UNREGISTER(escape_test);
return 0;
}
@@ -472,6 +505,7 @@ static int load_module(void)
AST_TEST_REGISTER(ends_with_test);
AST_TEST_REGISTER(strsep_test);
AST_TEST_REGISTER(escape_semicolons_test);
+ AST_TEST_REGISTER(escape_test);
return AST_MODULE_LOAD_SUCCESS;
}