<p></p>
<h3>Description</h3>
<p>We have some JS code looping over all P-Asserted-Identity headers removing some of the entries:</p>
<pre><code>    let headerIndex = 0;
    const telUriMatcher = new RegExp("tel:");
    let paiValue = ksr.pv
      .gete("$(hdr(P-Asserted-Identity)[" + headerIndex + "])")
      .toString();
    while (paiValue.length > 0) {
      ksr.info(
        `${ksr.pv.getw("$ci")}: Found P-A-I header with content <${ksr.pv.getw(
          "$(hdr(P-Asserted-Identity)[" + headerIndex + "])"
        )}> at index ${headerIndex}\n`
      );
      if (telUriMatcher.test(paiValue)) {
        ksr.info(
          `${ksr.pv.getw("$ci")}: Removed P-A-I header ${ksr.pv.getw(
            "$(hdr(P-Asserted-Identity)[" + headerIndex + "])"
          )}\n`
        );
        ksr.textopsx.remove_hf_value(
          "P-Asserted-Identity[" + headerIndex + "]"
        );
      }
      headerIndex++;
      paiValue = ksr.pv
        .gete("$(hdr(P-Asserted-Identity)[" + headerIndex + "])")
        .toString();
    }
</code></pre>
<p>In our tests, we wanted to remove the second header, but the first one got removed instead. The pseudovars docs say, the index of a header is 0-based. In textopsx docs it doesn't explicitly say, it's 1-based, but the first example shows it actually is.</p>
<h3>Possible Solutions</h3>
<p>Right now, we replaced the line</p>
<pre><code>ksr.textopsx.remove_hf_value("P-Asserted-Identity[" + headerIndex + "]");
</code></pre>
<p>with this one:</p>
<pre><code>ksr.textopsx.remove_hf_value("P-Asserted-Identity[" + (headerIndex + 1) + "]");
</code></pre>
<p>This solves the problem, but it is not what we would expect. Both header access methods should use the same index base.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.3.5 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, 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, TLS_PTHREAD_MUTEX_SHARED
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: unknown
compiled with gcc 8.3.0
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>Linux hostname 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) 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/2387">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZJP5F3OAPLPE2N7NZDRZSO3DANCNFSM4OO7IQLQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZPXNJ4OTRKVGACRR33RZSO3DA5CNFSM4OO7IQL2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4JV6I6HA.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/2387",
"url": "https://github.com/kamailio/kamailio/issues/2387",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>