gaaf created an issue (kamailio/kamailio#4444)

### Description

Trying to access a PV in numeric context is highly inconsistent in case the PV 
contains a string as well as a number. An examples of such PV's are $dP, $rP, 
$nh(P). These set the protocol as string and as number.


### Troubleshooting

#### Reproduction

The following script fragment logs the various interactions with such a PV.

```
xinfo("Target proto 1: $rP");    # "tls"

xinfo("Target proto 2: $(rP{s.int})");    # "tls"   WRONG!

$vn(rP) = $(rP{s.int});
xinfo("Target proto 3: $vn(rP)");    # 3

$vn(rP) = $rP;
xinfo("Target proto 4: $vn(rP)");    # "tls"

$vn(rP) = $rP + 0;
xinfo("Target proto 5: $vn(rP)");    # "tls0"  WRONG!

$vn(rP) = 0 + $rP;
xinfo("Target proto 6: $vn(rP)");    # 3

$vn(rP) = $rP + "";
xinfo("Target proto 7: $vn(rP)");    # "tls"

$vn(rP) = "" + $rP;
xinfo("Target proto 8: $vn(rP)");    # "tls"

$vn(isTLS) = $rP == "tls";
xinfo("Target is TLS 9: $vn(isTLS)");    # 1

$vn(isTLS) = $rP == 3;
xinfo("Target is TLS 10: $vn(isTLS)");    # 0   WRONG!

$vn(isTLS) = $(rP{s.int}) == 3;
xinfo("Target is TLS 11: $vn(isTLS)");    # 1

$vn(isTLS) = 3 == $rP;
xinfo("Target is TLS 12: $vn(isTLS)");    # 1

```


Resulting in the following log entries:
```
INFO: Target proto 1: tls
INFO: Target proto 2: tls
INFO: Target proto 3: 3
INFO: Target proto 4: tls
INFO: Target proto 5: tls0
INFO: Target proto 6: 3
INFO: Target proto 7: tls
INFO: Target proto 8: tls
INFO: Target is TLS 9: 1
INFO: Target is TLS 10: 0
INFO: Target is TLS 11: 1
INFO: Target is TLS 12: 1
```

Scenario's 2, 3, 5, 6, 10, 11, 12 all access the PV in numeric context, yet 
only 3, 11 and 12 yield the correct result.

Especially 2 is worrying as the clear intention of the author is to fetch a 
numerical value, not a string.

For 4 and 10 I can understand that the type of the first variable item used, 
but the script parser should throw an error as the concatenated value is not a 
string. The script parser should not convert a number to a string automatically.


And then there is also the fact that the whole numeric part gets lost on 
assignment to another PV:
```
$vn(rP) = $rP;
xinfo("Target proto 13: $(vn(rP){s.int})");

$vn(rP) = $(vn(rP){s.int});
xinfo("Target proto 14: $vn(rP)");
```

Log:
```
INFO: Target proto 13: 
ERROR: <core> [core/lvalue.c:346]: lval_pvar_assign(): non existing right pvar
ERROR: <core> [core/lvalue.c:404]: lval_assign(): assignment failed at pos: 
(734,13-734,28)
INFO: Target proto 14: <null>
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4444
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/[email protected]>
_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to