After some review and search (https://github.com/kamailio/kamailio/issues/1719), it seems that there is "bug" when trying to apply multiple changes at once (at least regarding the display name and URI as well). Since all changes are done in respect to the original message, some consecutive changes mess up the message.
An example is when first changing the URI and then the Display name.
<details>
<summary> See example config (kamailio master branch) </summary>
``` # kamailio.cfg request_route { xlog("From: $fu and $fn\n"); xlog("To: $tu and $tn\n"); $fu = "sip:testing@test.com"; $fn = "Displayname"; dbg_sip_msg(); ... } ``` `dbg_sip_msg()` applies the changes and produces the following: `From: sip:testing@test.comDisplayname #012` debug line.
The same can be observed if we forward the message to server itself and see the log `ERROR: {1 248 REGISTER al@there.com} <script>: From: sip:testing@test.comDisplayname and <null>` </details>
If we `apply_msg_changes()` though just after URI change, and then continue as normally, it behaves as expected.
With https://github.com/kamailio/kamailio-wiki/pull/57, I added some docs in the PV cookbook intro, about this workaround, as it's currently only in `textopsx` docs.