[SR-Users] Missing line in line.count transformation

Daniel Donoghue daniel.donoghue at freespee.com
Wed Oct 6 16:45:17 CEST 2021

I think I’ve found an edge case with the string transformations for line.count:

In pv_trans.c, the following code does not appear to consider the last line if there are multiple lines and the last one is not terminated with \n.

    for(i=0; i<val->rs.len; i++)
    if(n==0 && val->rs.len>0)
        n = 1;
    val->flags = PV_TYPE_INT|PV_VAL_INT|PV_VAL_STR;
    val->ri = n;
    val->rs.s = int2str(val->ri, &val->rs.len);

This means that my count is always one off unless I force a blank line at the end of my string.

Also, this code does not cater for cases where there is a different line terminator, such as CR or CRLF as is the case when the string comes from a Mac or windows system, respectively; it might be useful to have a transformation for doing that as I’ve had to hack it using s.replace with hexadecimal escape codes (\r and \n do not work) in a variable.

With every blessing,
Daniel Donoghue

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20211006/5f7f93da/attachment.htm>

More information about the sr-users mailing list