]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
say: Don't prepend ampersand erroneously.
authorNaveen Albert <asterisk@phreaknet.org>
Wed, 28 Sep 2022 12:38:37 +0000 (12:38 +0000)
committerN A <asterisk@phreaknet.org>
Wed, 26 Oct 2022 12:48:10 +0000 (07:48 -0500)
Some logic in say.c for determining if we need
to also add an ampersand for file seperation was faulty,
as non-successful files would increment the count, causing
a leading ampersand to be added improperly.

This is fixed, and a unit test that captures this regression
is also added.

ASTERISK-30248 #close

Change-Id: I02c1d3a11d82fe4ea8b462070cbd1effb5834d2b

funcs/func_sayfiles.c
main/say.c

index d3f3341a4d5064fc06bc8ac8171565933d666ac6..7e0ece2c966ae85e5d8b7c2161bcb5dbb5a37241 100644 (file)
@@ -211,6 +211,15 @@ AST_TEST_DEFINE(test_SAYFILES_function)
                res = AST_TEST_FAIL;
        }
 
+       /* + should be ignored and there should not be a leading & */
+       ast_str_set(&expr, 0, "${SAYFILES(+18005551212,digits)}");
+       ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
+       if (strcmp(ast_str_buffer(result), "digits/1&digits/8&digits/0&digits/0&digits/5&digits/5&digits/5&digits/1&digits/2&digits/1&digits/2") != 0) {
+               ast_test_status_update(test, "SAYFILES(+18005551212,digits) test failed ('%s')\n",
+                               ast_str_buffer(result));
+               res = AST_TEST_FAIL;
+       }
+
        ast_str_set(&expr, 0, "${SAYFILES(35,number)}");
        ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
        if (strcmp(ast_str_buffer(result), "digits/30&digits/5") != 0) {
index b60d4bff3c8e973e0d982b3bba3d8700bce77f0a..14e43dfff539aad4f71fd36e7ee06af12eb6b20f 100644 (file)
@@ -160,7 +160,7 @@ struct ast_str* ast_get_character_str(const char *str, const char *lang, enum as
                }
                if ((fn && ast_fileexists(fn, NULL, lang) > 0) ||
                        (snprintf(asciibuf + 13, sizeof(asciibuf) - 13, "%d", str[num]) > 0 && ast_fileexists(asciibuf, NULL, lang) > 0 && (fn = asciibuf))) {
-                       ast_str_append(&filenames, 0, (num == 0 ? "%s" : "&%s"), fn);
+                       ast_str_append(&filenames, 0, "%s%s", ast_str_strlen(filenames) ? "&" : "", fn);
                }
                if (upper || lower) {
                        continue;
@@ -282,7 +282,7 @@ struct ast_str* ast_get_phonetic_str(const char *str, const char *lang)
                        fn = fnbuf;
                }
                if (fn && ast_fileexists(fn, NULL, lang) > 0) {
-                       ast_str_append(&filenames, 0, (num == 0 ? "%s" : "&%s"), fn);
+                       ast_str_append(&filenames, 0, "%s%s", ast_str_strlen(filenames) ? "&" : "", fn);
                }
                num++;
        }
@@ -336,7 +336,7 @@ struct ast_str* ast_get_digit_str(const char *str, const char *lang)
                        break;
                }
                if (fn && ast_fileexists(fn, NULL, lang) > 0) {
-                       ast_str_append(&filenames, 0, (num == 0 ? "%s" : "&%s"), fn);
+                       ast_str_append(&filenames, 0, "%s%s", ast_str_strlen(filenames) ? "&" : "", fn);
                }
                num++;
        }