<h3>Description</h3>
<p>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 -> <a href="https://www.kamailio.org/wiki/tutorials/faq/main#how_to_iterate_through_the_ite" rel="nofollow">https://www.kamailio.org/wiki/tutorials/faq/main#how_to_iterate_through_the_ite</a><br>
It is expected that the access to an invalid index would return null.</p>
<h3>Troubleshooting</h3>
<p>avp and var variables were tried and both had the same result.</p>
<h3>Reproduction</h3>
<p>Original piece of code is below. The while loop will run until the max_while_loops is reached.<br>
The "DEBUG" log line will print the loop iterator value and an empty string for nonexistent values.</p>
<pre><code>        $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;
                }
        }
</code></pre>
<p>It is also possible to simulate it by simply doing this:</p>
<pre><code>        $var(allowed_headers) = "X-header1; X-header2;";
        if ($(var(allowed_headers){s.select,100,;}) != $null) {
                xlog("L_ERR","THIS IS WRONG :(");
        }
</code></pre>
<h3>Possible Solutions</h3>
<p>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....</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code># 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
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code># 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
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2128?email_source=notifications&email_token=ABO7UZOMBLPJJCJPMA3HAETQTR6YLA5CNFSM4JNCUPBKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZE5Z7Q">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZJNWNTBPQPR7VBBCWTQTR6YLANCNFSM4JNCUPBA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZNAIBPR2NXEYPG43RDQTR6YLA5CNFSM4JNCUPBKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZE5Z7Q.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2128?email_source=notifications\u0026email_token=ABO7UZOMBLPJJCJPMA3HAETQTR6YLA5CNFSM4JNCUPBKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZE5Z7Q",
"url": "https://github.com/kamailio/kamailio/issues/2128?email_source=notifications\u0026email_token=ABO7UZOMBLPJJCJPMA3HAETQTR6YLA5CNFSM4JNCUPBKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZE5Z7Q",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>