]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: sample: change the behavior of the bin2str cast
authorThierry FOURNIER <tfournier@exceliance.fr>
Wed, 12 Mar 2014 14:07:59 +0000 (15:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 17 Mar 2014 16:31:46 +0000 (17:31 +0100)
commite87cac16cc082fa43d5f65dd68e1244add7871c6
tree45eebb8620bac550f8a27604b373b3d2c70fb02d
parent2f49d6d17be8825a2c64ed89434d85959b8000f8
MEDIUM: sample: change the behavior of the bin2str cast

The bin2str cast gives the hexadecimal representation of the binary
content when it is used as string. This was inherited from the
stick-table casts without realizing that it was a mistake. Indeed,
it breaks string processing on binary contents, preventing any _reg,
_beg, etc from working.

For example, with an HTTP GET request, the fetch "req.payload(0,3)"
returns the 3 bytes "G", "E", and "T" in binary. If this fetch is
used with regex, it is automatically converted to "474554" and the
regex is applied on this string, so it never matches.

This commit changes the cast so that bin2str does not convert the
contents anymore, and returns a string type. The contents can thus
be matched as is, and the NULL character continues to mark the end
of the string to avoid any issue with some string-based functions.

This commit could almost have been marked as a bug fix since it
does what the doc says.

Note that in case someone would rely on the hex encoding, then the
same behaviour could be achieved by appending ",hex" after the sample
fetch function (brought by previous patch).
src/sample.c