diff options
author | Kinsey Moore <kmoore@digium.com> | 2014-10-10 13:03:18 +0000 |
---|---|---|
committer | Kinsey Moore <kmoore@digium.com> | 2014-10-10 13:03:18 +0000 |
commit | 37b5f52da76572dec98d3f182d788e81e0d8e369 (patch) | |
tree | 6c56e181ef15c7dc4c40f10e4f878d3ead285af4 | |
parent | 0ef680cff0d1bd1ccc69119cc45be895824eb266 (diff) |
CallerID: Fix parsing regression
This fixes a regression in callerid parsing introduced when another bug
was fixed. This bug occurred when the name was composed entirely of
DTMF keys and quoted without a number section (<>).
ASTERISK-24406 #close
Reported by: Etienne Lessard
Tested by: Etienne Lessard
Patches:
callerid_fix.diff uploaded by Kinsey Moore
Review: https://reviewboard.asterisk.org/r/4067/
........
Merged revisions 425152 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 425153 from http://svn.asterisk.org/svn/asterisk/branches/11
........
Merged revisions 425154 from http://svn.asterisk.org/svn/asterisk/branches/12
........
Merged revisions 425155 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425156 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | main/callerid.c | 16 | ||||
-rw-r--r-- | tests/test_callerid.c | 4 |
2 files changed, 16 insertions, 4 deletions
diff --git a/main/callerid.c b/main/callerid.c index 803d41195..a99dafc44 100644 --- a/main/callerid.c +++ b/main/callerid.c @@ -1007,12 +1007,20 @@ int ast_is_shrinkable_phonenumber(const char *exten) return ast_is_valid_string(exten, "0123456789*#+()-."); } -int ast_callerid_parse(char *instr, char **name, char **location) +int ast_callerid_parse(char *input_str, char **name, char **location) { - char *ls, *le, *name_start; + char *ls; + char *le; + char *name_start; + char *instr; + int quotes_stripped = 0; /* Handle surrounding quotes */ - instr = ast_strip_quoted(instr, "\"", "\""); + input_str = ast_strip(input_str); + instr = ast_strip_quoted(input_str, "\"", "\""); + if (instr != input_str) { + quotes_stripped = 1; + } /* Try "name" <location> format or name <location> format or with a missing > */ if ((ls = strrchr(instr, '<'))) { @@ -1028,7 +1036,7 @@ int ast_callerid_parse(char *instr, char **name, char **location) ast_copy_string(tmp, instr, sizeof(tmp)); ast_shrink_phone_number(tmp); - if (ast_isphonenumber(tmp)) { /* Assume it's just a location */ + if (!quotes_stripped && ast_isphonenumber(tmp)) { /* Assume it's just a location */ name_start = NULL; strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */ *location = instr; diff --git a/tests/test_callerid.c b/tests/test_callerid.c index 43b760d89..d0788a400 100644 --- a/tests/test_callerid.c +++ b/tests/test_callerid.c @@ -56,10 +56,14 @@ AST_TEST_DEFINE(parse_nominal) {"\"\" <number>", NULL, "number"}, {"<number>", NULL, "number"}, {"name", "name", NULL}, + {" name", "name", NULL}, {"\"name\"", "name", NULL}, + {"\"*10\"", "*10", NULL}, + {" \"*10\"", "*10", NULL}, {"\"name\" <>", "name", NULL}, {"name <>", "name", NULL}, {"1234", NULL, "1234"}, + {" 1234", NULL, "1234"}, {"\"na\\\"me\" <number>", "na\"me", "number"}, }; char *name; |