diff --git a/pbx.c b/pbx.c index dd8abbd4aa..2bc05ff5d9 100755 --- a/pbx.c +++ b/pbx.c @@ -3830,7 +3830,13 @@ int ast_add_extension2(struct ast_context *con, } e = con->root; while(e) { - res= strcmp(e->exten, extension); + /* Make sure patterns are always last! */ + if ((e->exten[0] != '_') && (extension[0] == '_')) + res = -1; + else if ((e->exten[0] == '_') && (extension[0] != '_')) + res = 1; + else + res= strcmp(e->exten, extension); if (!res) { if (!e->matchcid && !tmp->matchcid) res = 0;