summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2014-11-05 00:17:10 +0000
committerGeorge Joseph <george.joseph@fairview5.com>2014-11-05 00:17:10 +0000
commitd5de94201e969b3eeb6ffcef2b92c3b94694f5ce (patch)
tree83c69bee90a50cdf99f385195559d6b58cc879ed /tests
parentc77a71ad2fd330c20e8f5055044ede1c9ab495b0 (diff)
config: Make text_file_save and 'dialplan save' escape semicolons in values.
When a config file is read, an unescaped semicolon signals comments which are stripped from the value before it's stored. Escaped semicolons are then unescaped and become part of the value. Both of these behaviors are normal and expected. When the config is serialized either by 'dialplan save' or AMI/UpdateConfig however, the now unescaped semicolons are written as-is. If you actually reload the file just saved, the unescaped semicolons are now treated as start of comments. Since true comments are stripped on read, any semicolons in ast_variable.value must have been escaped originally. This patch re-escapes semicolons in ast_variable.values before they're written to file either by 'dialplan save' or config/ast_config_text_file_save which is called by AMI/UpdateConfig. I also fixed a few pre-existing formatting issues nearby in pbx_config.c Tested-by: George Joseph ASTERISK-20127 #close Review: https://reviewboard.asterisk.org/r/4132/ ........ Merged revisions 427275 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 427276 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@427277 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests')
-rw-r--r--tests/test_strings.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/test_strings.c b/tests/test_strings.c
index 127ee789d..05cc8df84 100644
--- a/tests/test_strings.c
+++ b/tests/test_strings.c
@@ -387,6 +387,74 @@ AST_TEST_DEFINE(strsep_test)
return AST_TEST_PASS;
}
+static int test_semi(char *string1, char *string2, int test_len)
+{
+ char *test2 = NULL;
+ if (test_len >= 0) {
+ test2 = ast_alloca(test_len);
+ *test2 = '\0';
+ }
+ ast_escape_semicolons(string1, test2, test_len);
+ if (test2 != NULL && strcmp(string2, test2) == 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+AST_TEST_DEFINE(escape_semicolons_test)
+{
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "escape_semicolons";
+ info->category = "/main/strings/";
+ info->summary = "Test ast_escape_semicolons";
+ info->description = "Test ast_escape_semicolons";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+
+ ast_test_validate(test, test_semi("this is a ;test", "this is a \\;test", 18));
+ ast_test_validate(test, test_semi(";", "\\;", 3));
+
+ /* The following tests should return empty because there's not enough room to output
+ * an escaped ; or even a single character.
+ */
+ ast_test_validate(test, test_semi(";", "", 0));
+ ast_test_validate(test, test_semi(";", "", 1));
+ ast_test_validate(test, test_semi(";", "", 2));
+ ast_test_validate(test, test_semi("x", "", 0));
+ ast_test_validate(test, test_semi("x", "", 1));
+
+ /* At least some output should be produced now. */
+ ast_test_validate(test, test_semi("xx;xx", "x", 2));
+ ast_test_validate(test, test_semi("xx;xx", "xx", 3));
+
+ /* There's still not enough room to output \; so
+ * don't even print the \
+ */
+ ast_test_validate(test, test_semi("xx;xx", "xx", 4));
+
+ ast_test_validate(test, test_semi("xx;xx", "xx\\;", 5));
+ ast_test_validate(test, test_semi("xx;xx", "xx\\;x", 6));
+ ast_test_validate(test, test_semi("xx;xx", "xx\\;xx", 7));
+ ast_test_validate(test, test_semi("xx;xx", "xx\\;xx", 8));
+
+ /* Random stuff */
+ ast_test_validate(test, test_semi("xx;xx;this is a test", "xx\\;xx\\;this is a test", 32));
+ ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;\\;", 32));
+ ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;", 10));
+ ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;\\;", 11));
+ ast_test_validate(test, test_semi(";;\\;;;", "\\;\\;\\\\;\\;\\;", 32));
+
+ ast_test_status_update(test, "This test should produce 2 'ast_escape_semicolons: FRACK!, Failed assertion' messages.\n");
+ ast_test_validate(test, !test_semi(NULL, "xx\\;xx", 8));
+ ast_test_validate(test, !test_semi("xx;xx", "xx\\;xx", -1));
+
+ return AST_TEST_PASS;
+}
static int unload_module(void)
{
@@ -394,6 +462,7 @@ static int unload_module(void)
AST_TEST_UNREGISTER(begins_with_test);
AST_TEST_UNREGISTER(ends_with_test);
AST_TEST_UNREGISTER(strsep_test);
+ AST_TEST_UNREGISTER(escape_semicolons_test);
return 0;
}
@@ -403,6 +472,7 @@ static int load_module(void)
AST_TEST_REGISTER(begins_with_test);
AST_TEST_REGISTER(ends_with_test);
AST_TEST_REGISTER(strsep_test);
+ AST_TEST_REGISTER(escape_semicolons_test);
return AST_MODULE_LOAD_SUCCESS;
}