Hello,
I am working on extending $hfl and $hflc supporting some more headers. During some experimentation, i stumbled in some weird behavior regarding $(hfl(Route)[-1]) and negative indexing of $hfl pseudo-variable.

Here is a breakdown of what's happening:

in kamailio.cfg:
  
request_route {
    xlog("L_INFO", "Route headers hdr: $hdr(Route)\n");
    xlog("L_INFO", "Route headers hfl: $hfl(Route)\n");
    xlog("L_INFO", "Route headers count: $hflc(Route)\n");
    xlog("L_INFO", "Route headers 0: $(hfl(Route)[0])\n");
    xlog("L_INFO", "Route headers 1: $(hfl(Route)[1])\n");
    xlog("L_INFO", "Route headers 4: $(hfl(Route)[4])\n");
    xlog("L_INFO", "Route headers -1: $(hfl(Route)[-1])\n");
    xlog("L_INFO", "Route headers -2: $(hfl(Route)[-2])\n");
    xlog("L_INFO", "Route headers -3: $(hfl(Route)[-3])\n");
    ...
}

Now when sending a SIP message containing multiple headers that have comma separated values ie:
OPTIONS_MSG_2CONTACTS="OPTIONS sip:example.com SIP/2.0
Via: SIP/2.0/UDP 192.168.1.100:5060;branch=z9hG4bK123456789
Max-Forwards: 70
From: <sip:bob@example.com>;tag=123456789
To: <sip:alice@example.com>
Call-ID: 987654321@192.168.1.100
CSeq: 1 OPTIONS
Contact: <sip:bob@example.com>;expires=3600,<sip:bob2@example.com>;expires=3600,<sip:bob3@example.com>;expires=3600
Route: <sip:server1.example.com;lr;ftag=1234>, <sip:server2.example.com;lr;ftag=5678>, <sip:server3.example.com;lr;ftag=9012>
Route: <sip:server4.example.com;lr;ftag=1234>, <sip:server5.example.com;lr;ftag=5678>
Content-Length: 0
"

the logs show the weird behavior: Negative -1 should print the last header found and so on (as stated by https://www.kamailio.org/wikidocs/cookbooks/devel/pseudovariables/#hflname-header-field-with-list-of-bodies $hdr $hfl doc).
Currently, -1 prints null and -2 prints the last one, -3 second to last and so on. This is probably a bug and not the expected behavior, or am i missing something?

INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers hdr: <sip:server1.example.com;lr;ftag=1234>, <sip:server2.example.com;lr;ftag=5678>, <sip:server3.example.com;lr;ftag=9012>
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers hfl: <sip:server1.example.com;lr;ftag=1234>
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers count: 5
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers 0: <sip:server1.example.com;lr;ftag=1234>
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers 1: <sip:server2.example.com;lr;ftag=5678>
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers 4: <sip:server5.example.com;lr;ftag=5678>
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers -1: <null>
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers -2: <sip:server5.example.com;lr;ftag=5678>
INFO: {1 1 OPTIONS 987654321@192.168.1.100} <script>: Route headers -3: <sip:server4.example.com;lr;ftag=1234>


Thanks,
Xenofon