<!-- Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for bug reports.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:
* http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
If there is no content to be filled in a section, the entire section can be removed.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment). -->
### Description When trying to iterate over a semi-colon separated string list, the s.select transformation seems to be returning empty string instead of null, so the suggested idea from here does not work -> https://www.kamailio.org/wiki/tutorials/faq/main#how_to_iterate_through_the_... It is expected that the access to an invalid index would return null.
### Troubleshooting avp and var variables were tried and both had the same result.
### Reproduction Original piece of code is below. The while loop will run until the max_while_loops is reached. The "DEBUG" log line will print the loop iterator value and an empty string for nonexistent values. ``` $var(allowed_headers) = "X-header1; X-header2;"; if (not_empty("$var(allowed_headers)")) { xlog("L_NOTICE","Forwarding headers: $avp(allowed_headers)\n"); $var(i) = 0; while($(var(allowed_headers){s.select,$var(i),;}) != $null) { xlog("L_NOTICE","DEBUG: $var(i) - $(var(allowed_headers){s.select,$var(i),;})\n"); $var(hdr) = $(var(allowed_headers){s.select,$var(i),;}{s.trim}); if (not_empty("$var(hdr)") && not_empty("$(hdr($var(hdr)))")) { xlog("L_NOTICE","Header: $var(hdr): $(hdr($var(hdr))) allowed\n"); append_hf("$var(hdr): $(hdr($var(hdr)))\r\n"); } $var(i) = $var(i) + 1; } } ```
It is also possible to simulate it by simply doing this: ``` $var(allowed_headers) = "X-header1; X-header2;"; if ($(var(allowed_headers){s.select,100,;}) != $null) { xlog("L_ERR","THIS IS WRONG :("); } ```
### Possible Solutions Other while conditions can be done. but this is the most elegant and is not working.... For example, checking with "not_empty" works, but then we can't actually have empty values in the semi-colon separated list because it would stop the loop and entries after that would not be reached....
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` # kamailio -v version: kamailio 5.2.2 (x86_64/linux) 67f967 flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: 67f967 compiled on 11:40:41 Mar 11 2019 with gcc 4.8.5 ```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `uname -a`) -->
``` # uname -a Linux voice-conn-kamailio-1 3.10.0-514.21.2.el7.x86_64 #1 SMP Tue Jun 20 12:24:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux ```
The example is wrong, indeed -- iirc, the transformations were not returning `$null` in the initial design, because they were supposed to be a property of a valid value. Not sure if there is any transformation returning `$null` right now.
However, changing this behaviour might break other existing configs, so this has to be discussed and analyzed properly.
Right now probably the `{s.count,;}` should be used to get what is the max index.
* https://www.kamailio.org/wiki/cookbooks/5.3.x/transformations#scount_c
I updated the example in FAQ with the working solution at this moment.
Thanks for the info Daniel. I created the ticket because I thought the behaviour had changed at some point, but if it was always like this it is fine. I will close the ticket now.
Closed #2128.